Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ByVAL v ByREF 1

Status
Not open for further replies.

JPJeffery

Technical User
May 26, 2006
600
GB
Please can someone tell me, or point me to a reference that tells me, what ByREF and ByVAL are for, what the differences are etc.?

JJ
[small][purple]Variables won't. Constants aren't[/purple][/small]
 
ByVal
the parameter is passed by value, thus the subroutine works with a copy of the original
ByRef
the parameter is passed by reference, thus the subroutine works directly with the original

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
So, if the subroutine is working continuously (somehow) it would always have the most up to date version of the variable?

But if that's right, what I don't understand (as a noobie) is how a subroutine would behave in this way. Surely the script would only continue after the subroutine has finished in which case the variable wouldn't have had the chance to change value...?

JJ
[small][purple]Variables won't. Constants aren't[/purple][/small]
 
you pass something to sub routine, in regards to script execution the sub routine is synchronuous/blocking method call type of thing, i.e. nothing will continue until sub has finished.

one way to look at it

+ if you want the sub routine to modify the thing you have passed to it then use RyRef.
+ if you dont want the sub routine to modify the thing you have passed it then use ByVal

there are performance implications with passing byVal and byRef and these differ based on the type of variable you are passing, some might say the difference between the type is arbitary in vbscript but i would guess that ByRef is faster as you arent allocating more momery?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top