你說的是按值傳遞(byval)跟按址傳遞(byref)嗎?
區別:
按值傳遞時(ByVal),形參的改變不會影響到實參
按址傳遞時(ByRef),形參的改變,會影響到實參
一個例子:
Private Sub Command1_Click()
Dim i As Integer
i = 10
Call test(i)
Print i
End Sub
Private Sub test(ByVal a As Integer)
a = a + 10
輸出10,形參的改變不會影響到實參
如果把Private Sub test(ByVal a As Integer)改成Private Sub test(ByRef a As Integer)
:
Private Sub test(ByRef a As Integer)
會輸出20,形參的改變,會影響到實參
你說的是按值傳遞(byval)跟按址傳遞(byref)嗎?
區別:
按值傳遞時(ByVal),形參的改變不會影響到實參
按址傳遞時(ByRef),形參的改變,會影響到實參
一個例子:
Private Sub Command1_Click()
Dim i As Integer
i = 10
Call test(i)
Print i
End Sub
Private Sub test(ByVal a As Integer)
a = a + 10
End Sub
輸出10,形參的改變不會影響到實參
如果把Private Sub test(ByVal a As Integer)改成Private Sub test(ByRef a As Integer)
:
Private Sub Command1_Click()
Dim i As Integer
i = 10
Call test(i)
Print i
End Sub
Private Sub test(ByRef a As Integer)
a = a + 10
End Sub
會輸出20,形參的改變,會影響到實參