10-26-2018 02:14 PM
Hi Group,
I am trying to implement in DIAdem script close to the same functionality that C/C++ has with contructs in .h files.
#ifndef HEADER_H_
#define HEADER_H_
// declarations #endif
The end goal is to be able to use scriptincludes to bring in outside code, but if the code block is already scriptincluded, then it will not repeat the scriptinclude.
This would simplify the code, as then would not have to make sure have all the scriptincludes only used once.
Was looking at using Globals or subsequence, but thought that those at NI would have the best way to implement something like this!
Paul
Solved! Go to Solution.
10-29-2018 03:35 PM
Hey Paul,
I don't know of a native, direct equivalent to C's pre-processor commands. I'm not surprised by that since vbscript is a script rather than a compiled programming language.
As for the includes, I found a general example here:
https://blog.ctglobalservices.com/scripting-development/jgs/include-other-files-in-vbscript/
This is the way that I've usually seen people do something like this.
As for adding the ifndef check, I would just use a regular vbs if statement and read/write a boolean variable.
10-31-2018 03:22 PM
Hi Bill B.
Thanks for the note!
Gave this some additional thought, and looks like can be implemented by wrapping the scriptinclude by a check to see that a global variable is present. The following script/sub should do the trick. I have not tested it, but it looks like it should work.
Background: The reason this is helpful, is that when you have a large amount of code, that is organized in Scriptincludes, it is easy to forget to include the file, and if do not have this guard feature, will end up having multiple functions that have the same name (because you scriptincluded the file more than once), (after all the script includes are done, and it gets very confusing, and hard to troubleshoot.
call ScriptInclude_check(Path_to_vbs)
sub scriptinclude_check(Path_to_vbs)
dim sFileNameMinusExt
sFileNameMinusExt = namesplit(Path_to_vbs,"N")
if not iteminfoget(sFileNameMinusExt) then
call scriptinclude(Path_to_vbs)
globaldim(sFileNameMinusExt)
end if
end sub
Paul
ps. I am interested to see what Dr. Brad or Andreas K think of this solution.
11-01-2018 07:12 AM
Hi Group,
Did some additional testing. Seems that if a file is scriptincluded more than once, that all after the first are not executed.
Is this the case?
Paul
11-05-2018 05:18 PM
Do you mean it runs without giving any errors?
Would it be better to store all scripts that have been included in an array and check for duplicates each time you call ScriptInclude?
11-06-2018 07:48 AM
Group,
In separate questions to those in Aachen, found that the files that are script included are already checked for already being scriptincluded. This has been confirmed in a small test I did.
So there then is not reason to have a guard like feature. The scriptinclude function already handles this concern.
Paul