02-24-2016 08:30 AM
Hello
I have two scripts A & B
When script A executes it calls script B using the "ScriptStart" command.
sometimes I execute script B on its own.
Is there anyway for script B to know it was called by script A without passing a global variable?
I am using DIAdem 2015
Thanks
02-24-2016 08:51 AM
I have figured out a way that get the job done but perhaps there are others?
Here is what I came up with
I was able to use the command ScriptCmdAdd in script A and then the command ScriptCmdIsLoaded in script B to check if it has been loaded.
It is worth noting I also used the command ScriptCmdRemove at the end of script A
02-24-2016 10:05 AM
My mistake.
The preceeding is not a desirable solution
02-25-2016 10:21 AM
Hi smooth,
I don't know any way for script B to know it was called by script A via ScriptStart().
Brad Turpin
DIAdem Product Support Engineer
National Instruments
02-25-2016 10:32 AM
Not a problem Brad
I was able to use as global variable to give me the desired result.
Basically I have a global variable in Script A , and Script B checks if this Global Variable exists by setting it to a local variable. If an error is thrown then I know that the global variable was not initialized therefore Script A could not have called Script B.
Thanks for looking at it nonetheless.
10-25-2020 05:30 PM
What is the proper way to use ScriptCmdIsLoaded ()? I cannot come up with a way for it to detect a script that I have registered with ScriptCmdAdd() has been loaded.
11-03-2020 07:55 AM
Hi Mark,
One option for you to consider it to add a argument to the script that is called in "ScriptCmdAdd" so that it will return some default value or boolean noting that it is actually present.
Alternatively, you could make a script that is added to file that tries to run the main script, with default values, and returns a boolean saying that the main script does indeed exist.
That should allow you to determine if script exists and is loaded, and then load it if not present.
paul
11-22-2020 03:40 PM - edited 11-22-2020 03:44 PM
Below is a solution. I ended up needed this capability for a large script based project.
'-------------------------------------------------------------------------------
'Script: MyScriptThatCallsLibrary.vbs
'Normal execution of function sVersionLibMechatronicSolutionsLLC()..
Call LogFileWrite("sVersionLibMechatronicSolutionsLLC() = " & sVersionLibMechatronicSolutionsLLC())
Call LogFileWrite(vbTab)
'Testing if sub/function sVersionLibMechatronicSolutionsLLC() exists..
Dim sFnOrSubName
sFnOrSubName = "sVersionLibMechatronicSolutionsLLC"
If bUserScriptHasBeenIncluded(sFnOrSubName) Then
Call LogFileWrite("Function/Sub '" & sFnOrSubName & "' exists in DIAdem script memory")
Else
Call LogFileWrite("Function/Sub '" & sFnOrSubName & "' does NOT exist in DIAdem script memory")
End If
'Testing if sub/function MySubThatDoesNotExist() exists..
sFnOrSubName = "MySubThatDoesNotExist"
If bUserScriptHasBeenIncluded(sFnOrSubName) Then
Call LogFileWrite("Function/Sub '" & sFnOrSubName & "' exists in DIAdem script memory")
Else
Call LogFileWrite("Function/Sub '" & sFnOrSubName & "' does NOT exist in DIAdem script memory")
End If
Function bUserScriptHasBeenIncluded(ByVal sFnOrSubName)
'Returns TRUE if function/sub sFnOrSubName exists in script memory.
'Create a function that returns a string in the library you want to monitor
'and add it to the script library you want to monitor.
bUserScriptHasBeenIncluded = False
If Not VarType(sFnOrSubName) = vbString Then Call Err.Raise(65535,,"ERROR - argument sFnOrSubName passed to bUserScriptHasBeenIncluded() is not a string")
Dim lErr, sErr
Dim sCmd, sVer
sCmd = "sVer = " & sFnOrSubName & "()"
On Error Resume Next
Call Execute(sCmd)
lErr = Err.number: sErr = Err.Description: On Error Goto 0
If lErr = 0 Then bUserScriptHasBeenIncluded = True
End Function
'-------------------------------------------------------------------------------
'Script: MyLibrary.vbs
Function sVersionLibMechatronicSolutionsLLC()
'Returns the current version of this custom script library.
'(Put this function into an included script library .. ScriptInclude("VbScriptLibWithThisFn.vbs") )
sVersionLibMechatronicSolutionsLLC = "20201122B"
End Function 'sVersionLibMechatronicSolutionsLLC()
11-23-2020 05:48 AM
Another approach:
'In the script where you want to check if the library has been included:
On Error Resume Next
Call Execute("T1=sVersionLibMechatronicSolutionsLLC()")
If Not Err.number = 0 Then Call ScriptInclude(CurrentScriptPath & "Lib_MechatronicSolutionsLLC.vbc")
On Error Goto 0
'Below put in the library to be checked:
Function sVersionLibMechatronicSolutionsLLC()
'Returns the current version of this custom script library.
'(Put this function into an included script library .. ScriptInclude("VbScriptLibWithThisFn.vbs") )
sVersionLibMechatronicSolutionsLLC = "20201122B"
End Function 'sVersionLibMechatronicSolutionsLLC()