sub Add1(ByVal no as int32) no=no+100 end sub sub Add2(ByRef no as int32) no=no+100 end sub private sub button1_click(sender as object,e as eventargs)handles button1.click dim a as int32 a=100 Add1(a) msgbox ("a的值为:" & a) '显示:a的值为100 Add2(a) msgbox ("a的值为:" & a) '显示:a的值为200,因为Add2中的参数no为ByRef,即 '按地址传递,因此在Add2中对no进行修改后,将会导致 '源参数a的值也被修改。 End Sub
Sub TestCopyMemory() Dim i As Long, k As Long k = 5 i = VarPtr(k) NOTE4: CopyMemory i, 40000, 4 Debug.Print k Debug.Print i i = VarPtr(k) NOTE5: CopyMemory ByVal i, 40000, 4 Debug.Print k End Sub