Contents | Index | < Browse | Browse >
Variables within variables
---------------------------
This is very usefull in many situations such as when you need "Arrays"
(or compound variables - or stem variables in arexx..)
As explained in Command lines Gui4Cli will consider $ as plain $.
It will not give it the significance that it starts a variable name.
Say you have a variable "X" which contains the name of another variable
(say "Y") and you want to know what is in that other variable (Y).
> Z = "$$X"
Gui4Cli will translate the above into:
> Z = "$Y"
i.e. the $ which is preceded by a slash will be written literally and
left to stand in front of the contents of $X, resulting in $Y. So,
to get at the contents of Y you could do:
> Z = $$X
> Say "X contains var $X which contains $Z'
This indirection is *very* usefull in many situations, since it allows
you to pass variable names as arguments, forming a sort of "array".
Example:
In GUI "One.gc"
> myvar.price = 1000
> myvar.date = "22/10/99"
> myvar.name = Dimitris
> gosub Two.gc MyRoutine "One.gc/myvar"
Now in GUI "Two.gc" we have a routine named "MyRoutine"
> xROUTINE MyRoutine VarName
As you read in passing arguments , when this routine is called, the
variable "VarName" will be initialised to contain "One.gc/myvar"
Now, this is how we can get at the contents of "myvar.price":
> price = $$VarName.price
Now variable "price" will contain "$One.gc/myvar.price"
So you can therefafter say:
> Say "myvar.price is equal to $price n"
And Gui4Cli will translate "$price" into "$One.gc/myvar.price", see
that there is a variable still untranslated and continue and translate
"$One.gc/myvar.price" into "1000", i.e. the value we want.
This may seem confusing and you'll seldom need it, but its there if you
ever do, because we, at Gui4Cli central headquarters, believe that it
is every programmers duty to... etc..