DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

SUD dialogs: how to refer controls of a dialog by code from a other dialog?

I have a simple problem, but don't find a solution. I try to manipulate objects of a dialog "Dlg1" by code of a other dialog "Dlg2".
 "Dlg1" and "Dlg2" are defined in same SUD-file. "Button1" is defindend in "Dlg2", but "Text1" is defined in "Dlg1".

Sub Button1_EventClick()
Dim This : Set This = Button1
    Call SUDDlgShow("Dlg1")
    Dlg1.text1.text = "test"
End Sub

This code don't work. I don't get a valid reference to the other dialog. I serch a solution.
A similar problem is to call a procedure defined in "declarations" of a dialog by a other dialog.

0 Kudos
Message 1 of 4
(3,250 Views)
Hello Martin!
 
What you want to do isn't possible! Two reasons: SUD Dialogs are no accessible objects and the SudDlgShow is a synchron command. The code after the SudDlgShow will be excuted after the dialog is closed. SUD dialogs are modal dialogs, that means only the last opened dialog is active and can execute script code. If you just want to pass values between dialogs you have to use variables (DIAdem or global script variables).
 
BTW: A good practice is to extract the script code out of the SUD into normal scripts and include them in the dialogs. Then it is possible to share code in several dialogs.
 
Matthias
Matthias Alleweldt
Project Engineer / Projektingenieur
Twigeater?  
0 Kudos
Message 2 of 4
(3,249 Views)
Hallo Mathias, thanks for your answer.

The first reason is the point! And it's a pity. What I want do do, is not to execute code of a other dialog, but to manupulate fields of the other dialog.
It is possible to open more then one dialog at the same time. Ok, only one dialog can be active, but other dialogs exist and ther fields exist too. If VBS could find out a valid pointer to this fields, my problem could be solved.  (This dos not mean, that changes of "Editbox1.text" take effect until it's dialog becomes active.)

I have a corresponding problem: It seams, that it is not possible to make global declarations for hole sud-file, isn't it?. I mean, declarations for all dialogs of a certain SUD-file.  I can make such declarations in a external vbs-file and include it with "scriptinclude()" in declaration part of every single dialog.  That is a way, but it is't nice.
0 Kudos
Message 3 of 4
(3,220 Views)
Hello Martin!
 
You sound a little bit SUD frustrated. I can understand this verry good because I had the same feelings years ago. After building some tools and exploring some (dirty) hacks  I'm now in the nice situation to ignore most limitations. The general thing to say is what the NI DIAdem R&D likes to say: SUD is a simple tool for creating GUIs for test rig automations or measurement calculations and not a sophisticated, state-of-the-art GUI programming system!
 
Back to reality. As far as I know is there no native way to declare SUD file variables. You have the choice to use global DIAdem variables (T1/L1/R1 or VAS or ODS_VallAlloc or GlobalDim). One aproach for a solution (DIAdem >=10) is to declare the variables with GlobalDim in the first dialog declaration section. Than you can use them in all sub dialogs. I like classes verry much so I would declare one variable and set it with an instance of a simple class containing just some variables (+initialization).
This can look this way:
'(Declarations)
Option Explicit
 
Call GlobalDim("MySudVars")
 
Set MySudVars = New CMySudVars
 
Class CMySudVars
  Public MyT1
  Public MyR1
  Public MyL1
  Public MyO1
  
  Public Sub Class_Initialize
    MyT1 = ""
    MyR1 = 0.0
    MyL1 = 0
    
    Set MyO1 = Nothing    
  End Sub
End Class
'End of (Declarations)
 
After this you can use MySudVars in all sub dialogs (e.g. MsgBox MySudVars.MyT1). You have full access from all dialogs!
Note: If you try to access the variable in the starting script you will see that it is still set. But if you want to read a value you get a runtime error. If you want to do this you must declare/set the variable in your script.
 
To be honest: For your other problem I know a tricky solution but I can't provide it here. I'm sorry!
 
 
Hope this help a little bit to reduce your SUD frustration
 
Matthias
Matthias Alleweldt
Project Engineer / Projektingenieur
Twigeater?  
0 Kudos
Message 4 of 4
(3,212 Views)