Call

Calls a WIL batch file as a subroutine.

Syntax:

Call ( filename, parameters )

Parameters:

(s) filename: the WIL batch file you are calling (including extension).

(s) parameters: the parameters to pass to the file, if any, in the form "p1 p2 p3 ... pn". (maximum value n = 9)

Returns:

(i)  can return a value, by specifying a value after the Return keyword in the called script. If no Return is specified the called script will return 0.

 

This function is used to pass control temporarily to a secondary WIL batch file. The main WIL program can optionally pass parameters to the secondary WIL batch file. All variables are common (global) between the calling program and the called WIL batch file, so that the secondary WIL batch file may modify or create variables. The secondary WIL batch file should end with a Return statement, to pass control back to the main WIL program.

If a string of parameters is passed to the secondary WIL batch file, it will automatically be parsed into individual variables with the names param1, param2, etc. The variable param0 will be a count of the total number of parameters in the string.

The Return command can return a value, by specifying a value (or an expression that evaluates to a value) after the "Return" keyword. The value or expression may optionally be enclosed in parentheses. This feature can be used with the Call command, and with the new user-defined functions . It does not affect the Gosub command.

Examples:

Return 

Return (10) 

Return "Okay" 

Return myvariable * 10 

Return (ItemCount(list, @TAB)) 

 

A script run with the Call command can return a value by using a Return command with a value (see above). If a Return command without a value is used, or the called script does not contain a Return command, the called script will return 0.

Note: To debug into a 'called' WinBatch script or user defined function, make sure to add the corresponding debug command, to the 'called script' or user defined function.

If compiling a script that contains the Call function, make sure to compile the called file using the Compiler option 'Encode for Calls from Exes'.

 

Example:


; File MAIN.WBT
;
; This example asks for user input, their name and age,
; and then calls another WinBatch job to verify if their
; age is between 0 & 150.
;
name = AskLine("", "What is your name?", "", 0)
age = AskLine("", "How old are you?", "", 0)
valid = @NO
Call("chek-age.wbt", age)
If valid == @NO Then Message("", "Invalid age")
Exit
;FILE CHEK-AGE.WBT
;
; This subroutine checks if the age inputted is between 0 & 150.
; If this is true, a global parameter is set to a value of 1.
userage = param1
really = AskYesNo("", "%name%, are you really %userage%?")
If really == @YES
   If (userage > 0) && (userage < 150)
      valid = @YES
   EndIf
EndIf
Return
See Also:

ParseData, Return, #Include, Encode for Calls from Exes