SPAWNS |
exitcode = SPAWNS( strStatements AS STRING, [par1, [par2]... ] ) AS INTEGER
Runs a Basic Sub Program in a separate thread with optional parameters. The Sub Program can return an INTEGER exit code using END [code] or STOP [code]. The Sub Program is passed to the function as a STRING compared to the SPAWN( ... ) function that passes the Sub Program as a file.
Sub Programs can access the arguments by declaring parameters by BYREF or BYVAL. Parameters are declared positional. For example
BYREF kalle AS STRING ' This is in/out first parameter passed BYVAL anka AS INTEGER ' in only second parameter passed
Uses "MyBASIC2_Run" environment variable to search for file if no folder is specified.
Example
' Run Hello World as a dynamically created Sub Program ' OPTION EXPLICIT ON
DIM s AS STRING
' Create string with PRINT "Hello World !",
s = "PRINT " + CHR( 34 ) + "Hello World !" + CHR( 34 ) + ","
' Print and Run the string
PRINT s, SPAWNS( s )
END |