What does ByRef mean in vbscript when passing to a procedure?

JoJo picture JoJo · Feb 27, 2012 · Viewed 6.9k times · Source

I have the following start to a procedure call

strReturn = OrderCreate(strGen8, _
                        strUID, _
                        Order, _
                        boolRecapFlag, _

And on the function that receives the parameters we have..

function OrderCreate(strCoDiv, strUID, byRef Order, boolRecap, strBillFirst, etc.

Since I could not find anywhere where Order values were getting passed into the prodcedure. Am I to assume that the ByRef makes it possible to bring data out of the procedure? Using the Order variable name?

Answer

Nilpo picture Nilpo · Feb 27, 2012

Parameters can be passed into a function in two ways: by reference (ByRef) or by value (ByVal). In VBScript, the default method is ByRef.

When you pass a value by reference, you are passing a reference that variables address in memory. This means that any changes made within your function will persist once your function exists. It can also be used to help control the way your script manages memory since data stored in a variable is only written once in memory.

Passing a parameter by value creates a copy of the variable in memory within the new scope. Changes made to this information within the new scope have no affect on the data in other scopes.