DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

ScriptInclude Guard like C++

Solved!
Go to solution

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

0 Kudos
Message 1 of 6
(2,691 Views)

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.

Bill B.
National Instruments
0 Kudos
Message 2 of 6
(2,659 Views)

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.

0 Kudos
Message 3 of 6
(2,641 Views)

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

0 Kudos
Message 4 of 6
(2,629 Views)

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?

0 Kudos
Message 5 of 6
(2,609 Views)
Solution
Accepted by topic author Pesmith8

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

0 Kudos
Message 6 of 6
(2,603 Views)