Passing a parameter by value

When a parameter is passed by value using the ByVal keyword, the called parameter obtains its own separate copy of the variable. The value of the variable can therefore be changed in the called procedure without affecting its original value in the calling procedure. This means that as in the function GetMaxSaleslnfo, when it changes the values of the parameters on lines 8 and 9, these changes also take place in the calling procedure. So in line 5 of TestMaxSaleslnfo, the two actual parameters theAddress and theRepname are also changed, when the function is called. The syntax for declaring a ByVal parameter is to insert the keyword ByVal before the parameter list is declared in the parentheses following the function name. If w e had a function called thisFunct that used a string parameter called myStr, and we wanted to pass this parameter by value, then the function declaration would be:

Function thisFunct (ByVal myStr as String)

0 0

Post a comment