Run

Program flow control function.

The Run function launches a compiled script as a sub-program.

Syntax

Run( "Script_name[.rob] [<Arg_1> <Arg_2> ...<Arg_n>]")
or
Ret=Run( "Script_name[.rob] [<Arg_1> <Arg_2> ...<Arg_n>]")

Parameters

"script_name", string, compiled script to be executed.

If the script name contains spaces, you must surround the name by CHR$(34):
Run(chr$(34)+"C:\program files\WinTask\scripts\my_script"+chr$(34))
The statement Run("script2"+""param1 param2"") would cause a compilation error since the character " is reserved for string definition ; you must replace the character " by its ASCII equivalent, so the correct statement is:
Run("script2"+chr$(34)+"param1 param2"+chr$(34)).
You can also see an example in the Shell function.

<Arg_n>: optional parameters for the compiled script; these parameters can be read by the Command$ function.

Return value

RetCode : numeric return code; 0 if the compiled script finishes correctly; or the value defined by the programmer using the End function. If "script_name" is empty, an error occurs at execution time (retcode=40). If the .ROB does not exist, no matter how #IgnoreErrors is set, an error message is displayed and the script is stopped.

Remarks

The values of system variables are valid only inside the script; so if a parent script calls a child script through Run, the values of system variables set up in the parent are not passed to the child script.

If you want to run an external program (a .EXE, a .BAT), use Shell function.

See also

Parameters passed from one script to another

Example

 

Result = Run("My_script userid pswd")

 

a$="my_script"

b$=a$ + " " + usrid$ + " " + pswd$

Result = Run(b$)

Example code

This example shows how to use the return code (End function)

Script1

 

File_to_find$="c:\program files\wintask\scripts\*.src"

 

Ret=Run("script2"+" "+chr$(34)+file_to_find$+chr$(34))

 

If Ret=-1 then

Mes$="Could not determine file count for "+file_to_find$

Else

Mes$="Number of file(s) "+File_to_find$+" : "+str$(Ret)

Endif

Msgbox(mes$)

 

 

Script2

 

Dim tab_name$(100)

Dim short_name$(100)

Dim att$(100)

 

#IgnoreErrors=1

Res=dir(command$(1), tab_name$(), short_name$(), att$(), "N")

 

' script2 return code is the return code of the Dir function

' Script1 can test for it

End(Res)