BYVAL
通過價值傳遞
- 
當值傳遞
ByVal時,過程會收到值的副本。Public Sub Test() Dim foo As Long foo = 42 DoSomething foo Debug.Print foo End Sub Private Sub DoSomething(ByVal foo As Long) foo = foo * 2 End Sub呼叫上述
Test過程輸出 42.DoSomething被賦予foo並接收該值的副本。副本乘以 2,然後在程式退出時丟棄; 來電者的副本從未改變過。 - 
當參考被傳遞
ByVal,程式接收一個拷貝的指標。Public Sub Test() Dim foo As Collection Set foo = New Collection DoSomething foo Debug.Print foo.Count End Sub Private Sub DoSomething(ByVal foo As Collection) foo.Add 42 Set foo = Nothing End Sub呼叫上述
Test過程輸出 1DoSomething是給定foo並接收一個拷貝的指標到Collection物件。由於Test範圍中的foo物件變數指向同一物件,因此在DoSomething中新增專案會將該專案新增到同一物件。因為它是指標的副本,所以設定它對Nothing的引用不會影響呼叫者自己的副本。