BCX Scripting Procedures

VBScriptControl Procedures

When any BCX VBS scripting procedure is invoked, the translator automatically adds the following define to the output C code.


 #ifndef _WIN32_DCOM
 #define _WIN32_DCOM
 #endif

VBS_ADDCODE function

Purpose: The VBS_ADDCODE function adds a block of code to the ScriptControl.


 Syntax:
 
 hResult = VBS_ADDCODE("VBScript string")

 Parameters:

  • hResult A returned positive number indicates that the function succeeded.
  • VBScript string block of code to be added to the ScriptControl.

Example:

VBS_ERROR function

Purpose: VBS_ERROR function returns a string containing the most recent error message from VBScriptControl.


 Syntax:
 
 RetStr$ = VBS_ERROR()

 Parameters:

  • RetStr$ is a string containing the most recent error message from VBScriptControl.

Example:

 
 DIM MY_VBScript$
 DIM GetVBSErr$
 DIM hResult AS HRESULT
 
 VBS_START
 
 MY_VBScript$ = "DIM X" & CRLF$ & " X = 3/0" ' <<< ZERO DEVIDE
 hResult = VBS_ADDCODE(MY_VBScript$)
   GetVBSErr$ = VBS_ERROR$()
   MSGBOX GetVBSErr$, "VBSCRIPT ERROR!",0 
 ? "FINISHED"
 VBS_STOP

VBS_EVAL_NUM function

Purpose: VBS_EVAL_NUM function evaluates a numeric expression.


 Syntax:
 
 RetVal# = VBS_EVAL_NUM("Variable name")

 Parameters:

  • RetVal# A result of the evaluation returned as a double number.
  • Variable name VBScript numeric variable to be evaluated.

Example:

VBS_EVAL_STR function

Purpose: VBS_EVAL_STR function evaluates a string expression.


 Syntax:
 
 RetStr$ = VBS_EVAL_STR("Variable name")

 Parameters:

  • RetStr$ A result of the evaluation returned as a string.
  • Variable name VBScript string variable to be evaluated.

Example:

VBS_RESET statement

Purpose: Reinitializes the scripting engine.


 Syntax:
 
 VBS_RESET

VBS_RUN_SCRIPT function

Purpose: VBS_RUN_SCRIPT will execute a subroutine declared in the ScriptControl.


 Syntax:
 
 RetStr$ = VBS_RUN_SCRIPT("SubAndArgs")

 Parameters:

  • RetStr$ Returned absolute(positive) value of Number.
  • SubAndArgs string containing name of subroutine and arguments declared in the ScriptControl.

VBS_START statement

Purpose: Initializes the scripting engine.


 Syntax:
 
 VBS_START

VBS_STOP statement

Purpose: Terminates the scripting engine.


 Syntax:
 
 VBS_STOP

Example:

 
 CLS

 VBS_START

 VBS_ADDCODE("Dim Mystring, Mydouble")
 VBS_ADDCODE("Dim I:For I = 65 To 65+25:Mystring=Mystring + Chr(I):Next")
 VBS_ADDCODE("Mydouble = Atn(1)*4")

 COLOR 11,0

 PRINT VBS_EVAL_NUM("Mydouble") 'displays  3.14159265358979
 PRINT VBS_EVAL_STR("Mystring") 'displays Abcdefghijklmnopqrstuvwxyz
 VBS_RESET

 VBS_RUN_SCRIPT("Msgbox " & ENC$("BCX Called VBSCRIPT MsgBox Function"))
 VBS_STOP

 COLOR 7,0

 KEYPRESS

Here's another quick example that shows how to read your VBSCRIPT file from disk and run it.

 
 DIM BUFFER$ * LOF ("YourVBScript.VBS")
 BUFFER$ = LOADFILE$("YourVBScript.VBS")

 VBS_START
   VBS_RUN_SCRIPT(BUFFER$)
 VBS_STOP