MACRO LIBRARY

Lesson 1.7 - ByVal vs Byref

Free public access. No account or subscription required.

Files

Lesson 1.7 - ByVal vs Byref

Code

'This demonstrates how to pass arguments between sub procedures
    
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
    
Dim A As Long
Dim B As Long
    
Sub CallingProcedure()
    A = 0
    B = 0
    MsgBox "BEFORE CALL" & vbCrLf & "A: " & A & vbCrLf & "B: " & B
    
    Call CalledProcedure(A, B)
    MsgBox "AFTER CALL" & vbCrLf & "A: " & A & vbCrLf & "B: " & B
End Sub
    
Sub CalledProcedure(ByVal X As Long, ByVal Y As Long)
    X = 1
    Y = 1
End Sub
    
'In short: ByRef will allow the value to be modified, ByVal will not