DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Classes in DIAdem user command files

I use classes in user command files.  I've successfully been using classes in user command files with DIAdem v9.  I'm in process of upgrading to DIAdem v11.  While running test cases I have a problem with this in v11.  I get the error message
 
"Class not defined"
 
However, the class is defined in a user command file.  Reading through literature, Microsofts VBScript engine did not support classes unless they were coded within the script that they were instantiated within.  However, version 5.6 of MicroSoft's VBScript engine allowed this.  I've been successfully doing this for months.
 
With the installation of DIAdem v11, I've noticed that the system directory no longer points to C:\Windows\System32.  Instead it points to the program files directory, e.g. C:\PROGRAM FILES\NATIONAL INSTRUMENTS\DIADEM 11.0.  I perused through this directory and found that the version of vbscript.dll was 5.5???????
 
So, I copied over the vbscript.dll (version 5.6) from my system 32 directory and pasted into the NI\DIADEM 11.0 directory and rebooted.
 
I still get the error message.
 
Does anyone know how I can get classes working when the class is coded in a user command file?  I absolutely have to get this to work in order to upgrade.
 
Thanks
0 Kudos
Message 1 of 4
(5,405 Views)

I've made a bit of progress.

In the script I am running I wanted to see if the user command file was actually registered.  Ofcourse, the user command file shows up when I look in the Settings->Options->Extensions->User Commands.  It is there and has a status of Loaded.  So I'm confident the user command file is loaded.  Maybe?

Anyway I use the following code to check within the script where I am using the command (which is actually a class)

Msgbox(ScriptCmdIsLoaded(ScriptLibrPath&"DP4Yaw_clslib.vbs")

While running the script, the message box pops up and displays the text "TRUE."  Unfortunately, when the script tries to execute the next line of code it halts and errors out and gives the error message that the class is not defined.

So, I then add another line of code just below the line to check if the user command file is loaded.  I added

Call scriptInclude(ScriptLibrPath&"DP4Yaw_clslib.vbs")

This makes all the difference.  It actually works now.  The class is instantiated, the script runs!

Why do I have to explicity run the scriptinclude command if the file is already loaded as a user command?  I don't have to do this with any of my user command files that contain subprocedures and functions, only the ones containing classes.  Also, this problem hasn't occurred with the earlier versions of DIAdem.  It seems as if the user command file is not truly being registered such that I can instantiate one of the class objects coded in the user command file. 

Thanks-Ryan37

0 Kudos
Message 2 of 4
(5,398 Views)
Hello Ryan!
 
In VBS it is only possible to instantiate classes wich are declared in the same script engine (and  namespace in DIAdem!). You can use instances across different engines. You have to undestand that in DIAdem user command extension scripts are running in a different script engine than the normal scripts. This avoid to instantiate a class defined in an user command extension script in a normal script. If you use ScriptInclude you insert the class defnition into your normal script -> you can instantiate the class. If you define a namespace in the ScriptInclude it will not work anymore! One aproach is to include all class definitions in your script. Another is to add functions into the class script as a class instance factory. This will work without any restrictions but is a little bit more work. Have a look at the following code
 
User command extension script:
Option Explicit
 
Class CMyClass
  Public Sub Test()
    MsgBox CStr(now)
  End Sub
End Class
 
Public Function MyClassNew()
  Set MyClassNew = new CMyClass
End Function
Normal script:
Option Explicit
 
Dim o
 
Set o = MyClassNew()
 
Call o.Test()
Matthias
Matthias Alleweldt
Project Engineer / Projektingenieur
Twigeater?  
0 Kudos
Message 3 of 4
(5,394 Views)
Thanks Mattias.
0 Kudos
Message 4 of 4
(5,365 Views)