Sub(V1): passed by value or by reference? 
Author Message
 Sub(V1): passed by value or by reference?

When we CALL SUB( V1, V2 )
Are the parameters passed by values or by references?
I found some documentation in MSDN Library saying that only passing by
values is supported, but my experiment reveals that passing by reference is
ok.

For example:
Sub PassHere( a, b, c )
 a = 21
 b = 22
 c = 23
End Sub

x = 11
y = 12
z = 13
Call Passhere( x, y, z )

At end of execution, x, y, z would be 21, 22, 23.
Since I use different variable names (x,y,z vs a,b,c), it is not possible
that global scope of variables is causing the effect.

Thanks
Peter Ty



Wed, 25 Jul 2001 03:00:00 GMT  
 Sub(V1): passed by value or by reference?
VBScript supports both Byref ans Byval meaning that a variable can be passed
both ways.  I believe that Byref is the default.  Try puttinb ByVal in front
of the variable names in the sub definition and try it again.  I think the
results should be different.

Sub PassHere( ByVal a, ByVal b, ByVal c )
 a = 21
 b = 22
 c = 23
End Sub

This wasn't always the case in VB.  Vb 3.0 had the default ByVal for
parameters.  When in doubt, specify the parameter mode.

HTH
--
Russell Greenlaw
http://rgreenlaw.home.mindspring.com
-------------------------------
Remove "nospam-" for e-mail replies.


Quote:
>When we CALL SUB( V1, V2 )
>Are the parameters passed by values or by references?
>I found some documentation in MSDN Library saying that only passing by
>values is supported, but my experiment reveals that passing by reference is
>ok.

>For example:
>Sub PassHere( a, b, c )
> a = 21
> b = 22
> c = 23
>End Sub

>x = 11
>y = 12
>z = 13
>Call Passhere( x, y, z )

>At end of execution, x, y, z would be 21, 22, 23.
>Since I use different variable names (x,y,z vs a,b,c), it is not possible
>that global scope of variables is causing the effect.

>Thanks
>Peter Ty



Wed, 25 Jul 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Sub(V1): passed by value or by reference?

2. passing objects by reference to a sub

3. Passing Values To TextBox from a Sub

4. Passing values to a sub or function using ONCLICK

5. Pass Session value to a VB Sub

6. Problems with passing parameters by reference to a sub program

7. Passing Value from Module Function to Form sub problem

8. Passing a value from a sub-report

9. Pass Sub-Report value to Main

10. Passing values from the sub report, onto the main report

11. Newbie Post: Passing Values back to Sub Main

12. Passing values by reference from java / vb script to ActiveX object

 

 
Powered by phpBB® Forum Software