回覆列表
  • 1 # 使用者2180107962444

    你說的是按值傳遞(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,形參的改變,會影響到實參

  • 中秋節和大豐收的關聯?
  • 你會在晚年回到家鄉居住嗎?為什麼?