DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Global Variables with SUD

I swear I've asked this before, but I cannot find my post from a previous user name... So, sorry if I am asking it again.  

 

I'm having a little difficulty using global variables between a parent script and a child SUD.  Here is what is happening:

  1. Declare global variable only if needed in the parent script
  2. Set global var to something like "test".
  3. using msgbox the global var is confirmed to say "test"
  4. Call dialog box using suddialogshow in the parent. The SUD contains a button and text box, text box contains the global var, and shows "test" like it should.
  5. click the button to use FileNameGet, set the global var to the File Name returned and call the text box's event refresh sub to set the text to global variable. The text box now contains the file name, as expected.  
  6. click the "x" in the upper right corner to close the dialog box.
  7. Using msgbox in the parent script, the global var is still "test"

For some reason, the parent script does not recieve the new value of the global var, even though the global var is the file name as confirmed using msgbox within the SUD.  

 

A couple things I figured out:

  1. If i use T1 for the diadem temporary variable, it works as expected, as in the parent script recieves the filename. 
  2. If i use Global Var=EditBox1.Text  in the Dialog_EventTerminate sub, the parent script also recieves the filename as expected.  

 

I want to understand this behavior and to make sure I'm doing things correctly, since I have MANY different global variables, and don't want to type them all into the Event Terminate sub.  

 

Thanks. 

0 Kudos
Message 1 of 8
(9,628 Views)

This feels wrong, but is my current workaround for this (R210_File is the global var), comment out the "R210_File=EditBox1.Text" and the parent script doesn't recieve the updated value. : 

 

Sub EditBox1_EventRefresh(ByRef This) 'Created Event Handler
  EditBox1.Text=R210_File
End Sub

Sub Dialog_EventTerminate(ByRef This) 'Created Event Handler
  R210_File=EditBox1.Text
End Sub

 

0 Kudos
Message 2 of 8
(9,627 Views)

Hi RussellSenior,

 

The best way to exchange information between a main script and SUD dialogs is the last parameter of the command "SUDDlgShow". This parameter is either a single variable or a VBS class which covers several variables. In the SUD you read this parameter in the dialog initialize event and write back the content of the dialog in the terminate event.

 

Please find attached an example for this kind of information exchange. (It is one of my standard examples extended with your request)

 

Greetings

Walter

Message 3 of 8
(9,614 Views)

I was afraid of that.  I'm not very confident making and using my own classes with Diadem.  Guess it's time to learn!

 

Thanks.

Message 4 of 8
(9,605 Views)

That is very nice example for transfer variables, which you don't need to save. E.g. it doesn't matter if these params is deleted after Diadem restart (or after calling ScriptCmdReset).

 

I'm usually working with user settings, which users expect to be same until user changes it.

 

For that I'm used to work with windows registry, where can I use tree structure of my params, look on current content and I know, that settings is always there.

 

Greetings

Radek

0 Kudos
Message 5 of 8
(9,559 Views)

That's an interesting approach, I never considered utilizing the registry. For user settings with Diadem, I usually create a text file to keep and store all the parameters.  I have to create my own functions to edit/read/write specific ini data.  It would be nice if Diadem had a set of built in functions for ini files.

0 Kudos
Message 6 of 8
(9,553 Views)

I've modified Walter’s script to use registry storage.

0 Kudos
Message 7 of 8
(9,535 Views)

Hi Russell,

 

I think the gotcha you ran into was that the SUDialog can be configured to restore the original states of specific global variables it knows about if the <Cancel> button is pressed.  First choose the menu "Edit >> Variables..." in the SUDialog Editor.  Now select the variable you wish to change and click the <Edit> button.  Finally uncheck the "Reset after cancel" checkbox and click the <OK> button twice and re-save the *.SUD file.

 

See if that helps,

Brad Turpin

DIAdem product Support Engineer
National Instruments

0 Kudos
Message 8 of 8
(9,500 Views)