Byval And Byref in Vb.net

Satyapriyanayak
Posted by Satyapriyanayak under VB.NET category on | Points: 40 | Views : 885
Public Class Form1
Dim x, y As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
x = 20
y = 30
MsgBox("Original value=" & x & " " & y)
change1(x)
change2(y)
MsgBox("Changed value=" & x & " " & y)
End Sub
Sub change1(ByVal x As Integer)
x = x + 10
End Sub
Sub change2(ByRef y As Integer)
y = y + 10
End Sub
End Class

Output

Original value= 20 30
Changed value= 20 40

Comments or Responses

Login to post response