Alex,

Yeah, I had the same thought as you - referencing a global variable from a function is "like" passing it by reference (kind of) ... but there's a BIG difference in the way I coded it as above. Using the above strategy, instead of passing the value of the variable, one passes the variable name itself as the parameter (by reference, it's like passing a pointer). The difference is that the UDF can be coded in a generic fashion. When hardcoding a specific global variable name in a UDF, that UDF will always be bound to that variable ...

I'm not saying that this is a viable or usable strategy, just throwing-out ideas and suggesting that this is one way to do it. By way of example, here's a UDF called AddOne() that will add 1 to any variable, without using a single hardcoded global variable ...


break on


$Variable1 = 1


AddOne("$$variable1")


?"Variable1=" $variable1


$Variable2 = 2


AddOne("$$variable2")


?"Variable2=" $variable2


exit 1


function AddOne($varbyref)
dim $local
$=Execute("$$local=$varbyref") ; assign global variable (value) to local
$local = $local + 1
$=Execute("$varbyref=$local")
endfunction

The global variable approach would have us do something like this (which is probably the better, easier, more understandable way anyways) :

$AddOneVar = $Variable1
AddOne()

$AddOneVar = $Variable2
AddOne()

Of course, AddOne() is a bad example to use here because normally, one wouldn't use global variables in a UDF that just adds one to a parmeter. This is just an example.

-Shawn

[ 15 January 2002: Message edited by: Shawn ]