Write VB program to swap the contents of variables using Pass by reference.

Write VB program to swap the contents of variables using Pass by reference.

Private Sub Command1_Click()

Dim A As Integer

Dim B As Integer

A = InputBox("Enter 1st Number")

B = InputBox("Enter 2nd Number")

Print "Before Swap A = " & A &"  B = " & B

Call Swap(A, B)

Print "After Swap A = " & A &"  B = " & B

End Sub

Sub Swap(ByRef X As Integer, ByRef Y As Integer)

Dim Temp As Integer

Temp = X

X = Y

Y = Temp

End Sub


Comments