ByVal vs ByRef VBA

后端 未结 4 1975
离开以前
离开以前 2021-02-09 21:25

I\'ve tried to attempt something that was answered by JaredPar ByRef vs ByVal Clarification

ByVal in VB.NET means that a copy of the provided

4条回答
  •  悲&欢浪女
    2021-02-09 22:00

    Change this:

    testingRoutine (trythis)

    to this:

    testingRoutine trythis

    then try it.

    Also, look what happens if I change it to this, where the function is being used as a function (returning something)

    Sub test1()
    
        Dim trythis As Boolean
        Dim testit As Boolean
    
        trythis = False
    
        If (Sheets("Sheet1").Range("A1").Value = 1) Then
            testit = testingRoutine(trythis)
            If (trythis) Then
                Debug.Print "Value changed to 0"
                Sheets("TESTING").Range("A1").Value = 0
            End If
        End If
    
    End Sub
    
    Private Function testingRoutine(ByRef trythis As Boolean) As Boolean
    
        Debug.Print "Ran Function"
        trythis = True
    
    End Function
    

提交回复
热议问题