DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Public Variables problem

I am trying to pass data from a SUD to a VBscript using a dynamic array defined as a Public variable. The array is defined in the VBscript that calls the SUD. In the SUD, I need to check to see if the array has any elements in it. If not I need to populate this array with items selected in a listbox. If the array has elements in it I need to read these elements out and take them out of the listbox so I only display "new" items. I can then fill the array again with new elements from the listbox. When finished I need to pass this array back to the VBscript that called it.

Thanks
AJL
0 Kudos
Message 1 of 13
(4,978 Views)
Hi AJL,

SUDialogs run in a different VBScript host from the VBScript that you run in DIAdem-SCRIPT, so simply declaring the array as a Public variable is not enough. Basically, the VBScript running in DIAdem-SCRIPT, the DIAdem command engine, and any SUDialogs are each a separate island, which can only be connected with global DIAdem variables. There are 4 types of global DIadem variables:

1) VAS variables, declared by a VAS file
2) OdsValAlloc variables, declared by the OdsValAlloc() function
3) User Variables, declared in a registered UserCommand VBScript file
4) GlobalDim variables, declared by the GlobalDim() function

Types 1) and 2) are explicitly datatyped and have been available in DIAdem forever. Types 3) and 4) are both brand new features in DIAdem 9.1 (which if I remember correctly you have). These are the best options, as they create a global variant variable. Variant variables in VBS can have up to 60 dimensions, can be redimensioned on-the-fly, reassigned to a different type of variable (scaler, array, etc.) or even declared a global object variable or array of objects variable.

For Type 3) you just declare a variable with global scope in the UserCommand VBScript file with Dim and ReDim, in the same way you would declare a global variant variable in any VBScript. By default DIAdem ships with an example UserCommand VBScript file (...DIAdem\libr\aut\UserCommandExample.VBS), though you can create your own and add them to the UserCommand registration list interactively or programmatically with the ScriptCmdAdd() function.
Example:
--------------------
ReDim foo(5)
foo(1) = "Element1"
foo(2) = "Element2"
foo(3) = "Element3"
foo(4) = "Element4"
foo(5) = "Element5"

For Type 4) you use the brand new DIAdem 9.1 functions GlobalDim() and GlobalReDim() to create the same global variant as in 3) but from any VBScript running in DIAdem-SCRIPT.
Example:
--------------------
GlobalReDim "foo(5)"
foo(1) = "Element1"
foo(2) = "Element2"
foo(3) = "Element3"
foo(4) = "Element4"
foo(5) = "Element5"

Now from any other VBScript or from a SUDialog this global variant variable is available and maintains its stored values until DIAdem shuts down or the ScriptCmdReset() function is called. Note that the ScriptCmdReset() function will destroy any Type 4) global variant variable, but it will only delete the contents (but not the dimensionality) of a Type 3) global variant variable, leaving the variable available for future use.
Example:
--------------------
MsgBox Join(Foo, vbCRLF)

Let me know if you have additional questions,
Brad Turpin
DIAdem Product Support Engineer
National Instruments
0 Kudos
Message 2 of 13
(4,951 Views)
I can not get the following statement to work. It will only dimension the array for one element (element zero). How can I redim the array dynamically to the size of "count"?

GlobalRedim("YCH(count)") 'count is the number of elements in a listbox

Thanks,

AJL
0 Kudos
Message 3 of 13
(4,926 Views)
Hi AJL,

What I noticed when I ran your code was that DIAdem declared both variables "YCH" and "count". In declaring the "count" variable to be global (which you did not intend, but apparently we can not avoid) the original value stored in "count" in the parent VBScript was lost. If you first declare the variable "count" as global, then fill it with the desired array length value, then issue the GlobalDim "YCH(count)" command, it will work.

Alternately, you can use one of the existing DIAdem temporary variables, i.e.

L1 = 10
GlobalDim "YCH(L1)"
MsgBox UBound(YCH)

Cheers,
Brad Turpin
DIAdem Product Support Engineer
National Instruments
0 Kudos
Message 4 of 13
(4,909 Views)
Thanks Brad. Using a DIAdem temporary variable worked for what I needed.
0 Kudos
Message 5 of 13
(4,896 Views)

Well its time to dust off an old thread I started.  Brad's solution worked way back when this thread was created (using Diadem 9.1) but now I am upgrading to Diadem 2010 and some of my scripts no longer work.  I traced it down to the ScriptCMDreset() function.  In Diadem 2010 I get an error stating this command cannot execute because other user commands are running and cannot be reset.  I don't call any user commands in my scripts.  Is there something in DIAdem 2010 that has changed from 9.1 that the ScriptCMDreset() will no longer work properly?

 

Has anyone else run across this?

 

Thanks in advance

 

AJL

0 Kudos
Message 6 of 13
(4,005 Views)

Hi AJL,

 

I just tested running ScriptCmdReset in DIAdem 2010, and it executed without error on my computer, so there must be SOMETHING different going on at your end.  It is possible to dynamically create and declare UserCommands, so maybe a script is running that creates a UserCommand that you're not aware of.

 

If you choose the menu "Settings>>Options>>Extensions>User Commands...", what do you see in that dialog?

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 7 of 13
(3,965 Views)

Thanks Brad.  I have looked at the mentioned location and a "usercommandexample" is running on startup.  I deleted this but still have the same problem.  I will do some more digging and see if any other user command is running.

 

On another note, will the diadem connectivity toolkit 3.0 for LabVIEW 7.1 work with Diadem 2010 (11.2)?  When I tried this I get a Diadem connectivity open VI reference error.

 

Thanks,

 

AJL

0 Kudos
Message 8 of 13
(3,961 Views)

Hi AJL,

 

I would have expected the LabVIEW Connectivity VIs for LC 7.0 to work with DIAdem 2010, mainly because very little has changed in the DIAdem ActiveX server.  There are newer versions of the LabVIEW Connectivity VIs that you might be able to use which were tested against DIAdem 2010.  What is the newest version of LabVIEW that you can use?

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 9 of 13
(3,953 Views)

The newest version I can use is LV7.1.  I am trying to get the LV developers to upgrade though.  An interesting thing I discovered yesterday was that if I call the LV VI from DIAdem the VI gets parameters from DIAdem but I cannot return any data. The error I get when called from DIAdem is an 8088 DIAdem Interface connection fail.  However, if I have DIAdem open but run the VI from LV everything works fine.   

 

Next calling LV from DIAdem and if I don't pass my errors from VI to VI I get the error message for the 8088 but everything works and returns the correct data to DIAdem. 

0 Kudos
Message 10 of 13
(3,942 Views)