PASSING ARGUMENTS : =================================================================== Arguments can be passed by the following commands : GUILOAD to xONLOAD or xONRELOAD GUIOPEN to xONOPEN GUICLOSE to xONCLOSE GUIQUIT to xONQUIT GOSUB to xROUTINE The way this is done is by declaring the arguments in the command's command line, like so GUILOAD guis:MyGui Arg0 Arg1... Arg5 or GOSUB MyGui MyRoutine My_Arg My_Other_Arg Up to 6 arguments may be passed. Inside the event they call, these arguments can be accessed in either of two ways : 1. As Arguments in the Event's definition. If declared in the event's definition, they'll be automatically converted to variables. For example : > xONLOAD Var1 Var2 If you were to call this event with : > GUILOAD MyGui.gc SomeText "Some more text" then when MyGui.gc loads, there would be 2 variables created : - "Var1" which would contain the word "SomeText" and - "Var2" which would contain "Some more text" You can also pass variables: > gui/myvar = "Some text" > GOSUB MyGui.gc RoutineName $gui/myvar If you pass variables you should use the variable's *full* path (as is done above) to avoid confusion. 2. As internal variables $$ARG.0 to $$ARG.5 Note that even if you define variables in the event's definition as above, they'll still be available as $$ARG.xx also. $$ARG.TOT will (always) contain the actual number of arguments passed. Furthermore, the above events (xONLOAD, xROUTINE etc) can now RETURN arguments via the RETURN command. RETURN Arg0 Arg1... Arg5 The arguments can be accessed (when they return to the routine that called the event) as internal variables $$RET.0 to $$RET.5. $$RET.TOT will contain the actual number of arguments returned. Example : xBUTTON 10 10 60 12 Test var = "This is a test" GoSub MyGui routine1 $var ; We only pass "var" as an argument here. We could have had up to 6 args. ; the routine will return one argument to us (also could have been 6) ; which we just print.. say 'Return returned $$RET.0\n' xROUTINE routine1 MyVar ; here variable "MyVar" will contain $var (i.e. "This is a test") ; Note that $$ARG.0 will also contain the same thing. say '$MyVar is the same as $$ARG.0\n" ; now we return something... Return "Thank you.." ** WARNING : - If you want to pass a variable you should give the variable's full path (i.e. RETURN MyGui/MyVariable), since it may be in another gui which may not have you in it's varpath. ** WARNING 2: - You can not pass an $$ARG.0 type of internal variable you receive as an argument to an other routine/xonload etc. : > GOSUB mygui myroutine $$ARG.0 <-* is WRONG That's because when Gui4Cli attempts to translate the variable when it gets to the routine, it will find variable $$ARG.0 containing $$ARG.0 and it will go into a wild loop trying to translate it.. This loop will time out after 100 rounds (i.e. the default depth of variables within variables that you can have) and the error will be reported. There are no such problems if you use the definition in the event's command line, so use that instead.