11
What's New / Re: ScriptBasic Core Windows 32 bit - Asynchronous Thread
« Last post by Support on May 25, 2021, 03:28:00 PM »This example creates a ScriptBasic asynchronous thread from a string of source code, sets / gets variables and calls a function.
C:\sb_build\examples>sbc sbt_demo.sb
123
1.23
One, Two, Three
Function Return
321
32.1
Three,Two,One
C:\sb_build\examples>
Code: Script BASIC
- ' SBT - Create and call child process script as text source
- IMPORT sbt.sbi
- sb_code = """
- FUNCTION prtvars(a, b, c)
- PRINT a,"\\n"
- PRINT FORMAT("%g\\n", b)
- PRINT c,"\\n"
- prtvars = "Function Return"
- END FUNCTION
- a = 0
- b = 0
- c = ""
- """
- sb = SB_New()
- SB_Configure sb, "C:/Windows/SCRIBA.INI"
- SB_Loadstr sb, sb_code
- SB_NoRun sb
- ' Call function before running script
- funcrtn = SB_CallSubArgs(sb,"main::prtvars", 123, 1.23, "One, Two, Three")
- PRINT funcrtn,"\n"
- ' Run script initializing globals
- SB_Run sb, ""
- ' Assign variables values
- SB_SetInt sb, "main::a", 321
- SB_SetDbl sb, "main::b", 32.1
- SB_SetStr sb, "main::c", "Three,Two,One" & CHR(0)
- ' Call function again with variables assigned in the previous step
- SB_CallSubArgs sb, "main::prtvars", _
- SB_GetVar(sb, "main::a"), _
- SB_GetVar(sb, "main::b"), _
- SB_GetVar(sb, "main::c")
- SB_Destroy sb
C:\sb_build\examples>sbc sbt_demo.sb
123
1.23
One, Two, Three
Function Return
321
32.1
Three,Two,One
C:\sb_build\examples>