Jump to content
Sign in to follow this  

byRef - a Better Explanation

Recommended Posts

Could anyone please clarify what ByRef means? I read and reread the documentation on it. I may be a bit slow :) , but I'd really like to understand this "attribute" and not just use it.


The ByRef keyword is optional and means: (1) the parameter must a variable, and (2) the original variable is linked to the parameter, so that any changes to the parameter inside the function, would affect the original variable as well. By default, a parameter is passed by value which means that a copy of the parameter's value, is manipulated by the function.

The order of the ByRef and Const keywords is not important, so long as they are in front of the variable they modify.

A decision is a powerful thing

Share this post

Link to post
Share on other sites

It means "By Reference".

You can pass a variable to a function by reference, it's like using pointers.

Let's say you have a variable called $var and a function called IncrementFunction which increments a variable. If you do:

$var = 0
$var2 = IncrementFunction ($var)

MsgBox (0, "DEBUG", $var & " -> " & $var2)

Func IncrementFunction ($number)
    $number = $number + 1
    Return $number
EndFuncoÝ÷ ÚØ^Mú½ªöÈ(v{V§wMú½ªâ²
'¦ÞÑ·j붺w-â²·z+â¯j[Z½ªâi¹^ëbØb±Æ¬y«­¢+ØÀÌØíÙÈôÀ(ÀÌØíÙÈÈô%¹Éµ¹Ñչѥ½¸ ÀÌØíÙȤ()5Í   ½à À°ÅÕ½Ðí UÅÕ½Ðì°ÀÌØíÙȵÀìÅÕ½Ðì´ÐìÅÕ½ÐìµÀìÀÌØíÙÈȤ()Õ¹%¹Éµ¹Ñչѥ½¸¡  åIÀÌØí¹ÕµÈ¤(ÀÌØí¹ÕµÈôÀÌØí¹ÕµÈ¬Ä(IÑÕɸÀÌØí¹ÕµÈ)¹Õ¹

$var2 AND $var1 are going to be 1, because the function received $var by reference. It means the function modified $var itself rather than a copied value.

[quote name='Valik' post='301213' date='Jan 31 2007, 10:36 PM']You seem to have a habit of putting things in the wrong place. I feel sorry for any female you attempt to have sex with.[/quote][font="Lucida Sans Unicode"][/font]

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Create New...