Command: ScriptInclude

DIAdem 2018 Help

Edition Date: June 2018
Part Number: 370858P-01
View Product Info

DOWNLOAD (Windows Only)

DIAdem 2017 Help
DIAdem 2018 Help
DIAdem 2019 Help
DIAdem 2020 Help
DIAdem 2020 SP1 Help

Integrates a script in another script.

Call ScriptInclude(ScriptFile, [ScriptScope])

Input Parameters

ScriptFile Specifies the name of a script file.
[ScriptScope] Specifies the name space of a script. By default the ScriptCode variable contains an empty text.
String variable
Maximum 255 characters

Use the name space to distinguish between procedures that have the same names, in different script files.


The following example assumes that the MyFunc function is in the Test.vbs script as well as the MyLib.vbs script. You can use the name space to distinguish between the two functions. In the example, the MyResult variable receives the result of the MyFunc function in the Test.vbs file and the MyOtherResult variable receives the result of the MyFunc function in the MyLib.vbs file. 

Dim MyResult
Dim MyOtherResult
ScriptScope = "Test"
Call ScriptInclude("Test.vbs",ScriptScope)
ScriptScope = "GlobalLib"
Call ScriptInclude("MyLib.vbs",ScriptScope)
MyResult = Test.MyFunc
MyOtherResult = GlobalLib.MyFunc

When the ScriptInclude command is called, DIAdem provides the main script with all the global variables, procedures, and functions in the subscript, and initializes the variables. When ScriptInclude is called, you can access these variables, procedures, and functions in the main script. If you specify the script file without a filename extension, DIAdem first searches for the file with the filename extension .vbs and then for the encrypted file with the filename extension .vbc.


If you start the main script Main.vbs, DIAdem uses the ScriptInclude command to register all the procedures and variables in the Function_Library.vbs subscript. You can then access the GetChnName routine and the strChannelName variable from the main script. If you try to start the Function_Library.vbs subscript, an error message informs you that you cannot execute a subscript. 

Contents of the Main.vbs file

Option Explicit
' Register all functions and procedures of Function_Library.vbs
Call ScriptInclude("Function_Library")
' Calling the function  
Call GetChnName(1)
Call MsgBoxDisp(strChannelName)
Call GetChnName(5)
Call MsgBoxDisp(strChannelName)

Contents of the Function_Library.vbs file

Option Explicit
' Labelling as subscript
Call Subsequence()
' Initialization
Dim strChannelName
' Procedure for evaluating a channel name
Sub GetChnName(intChannelNo)
  strChannelName ="<Channel does not exist!>" ' Initialize string
  If intChannelNo <= GlobUsedCHn Then         ' Less then maximum channel number
    strChannelName = ChnName(intChannelNo)
  End If
End Sub
Note  Call the ScriptInclude command only once at the beginning of a script for each script to be included. Do not call the ScriptInclude command in loops. The following table describes when to use the ScriptStart command instead of the ScriptInclude command. If you use the ScriptInclude command instead of the ScriptStart command you can speed up scripts.
ScriptStart ScriptInclude 
  XWhen you use transfer parameters
  XWhen you use return values
  X When you debug calls in another script
  X When you use name spaces
  X When you use objects and variables from another script
X   When you start a script as program parameter
X   When you specify menus, buttons, and other controls to start a script
X   When you call scripts via OLE
X   When you cancel the started script or local error for this script

Related Topics

Command: ScriptStart | Command: ScriptStatement | Command: SubSequence | Variable: ScriptFile | Variable: ScriptScope | Variable: Statement | Variable: SubSequenceText


Not Helpful