call statement

i'm taking a beginners course at a college and im trying to figure out how to use the call statement to get a variable passed by value from form1 to form2, keeping the same initial value i gave it. The book i was reading got really confusing on this topic. Can someone put it into simpler terms for me to understand.

-Thanks

Comments

  • : i'm taking a beginners course at a college and im trying to figure out how to use the call statement to get a variable passed by value from form1 to form2, keeping the same initial value i gave it. The book i was reading got really confusing on this topic. Can someone put it into simpler terms for me to understand.
    :
    : -Thanks
    :
    ----
    hi,
    VB6 by default passes variables by reference. In other words, any change of value inside the called function will be reflected on the variable that is being passed as a parameter.

    But VB.NET works the opposite way. It passes arguments/parameters (both are same) BY VALUE. So any manupulations or calculations performed on the variable that is passed as a parameter will not be reflected on the actual value present in the variable. In other words its scope ends within the procedure.

    for eg., lets say in form1, you have procedure

    sub CallingProcedure()
    dim intValue as integer
    dim frm2 as new form2 'Creating an object to call the procedure in form2

    intValue = 10

    frm2.Calculate(intvalue)
    end sub

    similarly, you have another procedure in form2.

    sub Calculate(intValue as integer)
    intvalue = intvalue + 10
    msgbox (intvalue)
    end sub

    in the above code, inside the callingprocedure (in form1), u r calling the Calculate(form2) procedure, by passing an int value. The VALUE IS PASSED BY VALUE, i.e, only the value is passed and not the reference.

    Henceforth, an addition of 10 to the variable will not affect the actual intValue declared in the Called Procedure.

    bye..







Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion