2
Reply

what is call by value and call by reference ?

vijay channe

vijay channe

14y
5.6k
0
Reply

    The ByVal keyword indicates that an argument is passed in such a way that the called procedure or property cannot change the value of a variable underlying the argument in the calling code.

    The ByRef keyword indicates that an argument is passed in such a way that the called procedure can change the value of a variable underlying the argument in the calling code.

    Example

    Public Class Form1
        Inherits System.Windows.Forms.Form
        Dim x, y As Integer

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            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

    By value means a variable or object is having copy of value and by reference mean having only address of value.