DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Problems passing variable value to SUD

Solved!
Go to solution

Hello,

 

I need some help understanding how to pass a variable to a SUD file. My main script sets the value of a variable (named KSTM) and it then uses SUDDlgShow to call a dialogue box. I need the sub script in the SUD file to be aware of the value of KSTM and act on it accordingly.

 

I've read about using transfer parameters, receiving them using GetArgument, and tried to understand the difference between ByRef and ByVal in case that's important. However, all I get is a range of error messages.

 

The value of KSTM does not need to be modified by the SUD file or passed back to the main script.

 

The code in the main script is:

 

KSTM = 1
Call SUDDlgShow("Parameters", SharedPath & "VBS\" & "Trans.sud", KSTM) 

 

I would then like to use the minimum amount of code in my SUD file to read the value of KSTM and act on it:

 

Sub Dialog_EventInitialize(ByRef This) 'Created Event Handler
  
  If KSTM > 0 Then
    EditBox7.Enable	= 1
    R1 = 1
  Else
    EditBox7.Enable = 0
    R1 = 99
  End If

End Sub

 

The above sub script in the SUD file fails because it says the variable KSTM is undefined. This is odd because KSTM is defined in the main script and I'm passing it to the SUD file. I'd be concerned about using Dim inside the sub script because I don't want to delete the contents of KSTM. However, since everything I try fails to overcome this error I have to conclude that I need to redim KSTM in the sub script. However, do I redim it above the subscript or inside it?

 

If I put it inside the subscript then I can get the code to work but it's obviously not correct. The value of R1 is telling me that it doesn't matter what value KSTM has in the main script it isn't getting passed to the subscript.

 

If I then add a set statement and use Dialog.GetArgument with it, I get a new error message telling me "Object required: 'Dialog.GetArgument'. I don't understand why this is a problem as this line is identical to one used in another script that works fine!

 

I have been through this before here (https://forums.ni.com/t5/DIAdem/Variable-types-and-variable-use-in-SUD-files/m-p/4022490#M27259) but on this occasion I only want to pass a single variable value and I don't need to pass anything back. Clearly, I didn't understand it very well the first time around.

 

Any help gratefully received.

 

Thanks, Simon.

 

 

 

 

0 Kudos
Message 1 of 4
(2,504 Views)

I think I have made some progress. It seems that if I define KSTM as a global variable, using GlobalDim at the head of my main script, then it's value can be seen by the SUD and I don't need to pass it to SUD in the SUDDlgShow call.

 

However, I'd be grateful if someone could explain if it's possible to pass a variable to SUD without having to define a class. I assume the last argument in SUDDlgShow can be used to pass a variable?

 

Regards, Simon.

0 Kudos
Message 2 of 4
(2,496 Views)
Solution
Accepted by topic author Simon_Aldworth

 

Sub Dialog_EventInitialize(ByRef This)
  Dim argument
  argument = This.GetArgument()
End Sub

 

I would assume that argument would get the values of KSTM.

Doesn't it?

 

If you use an class obect as parameter you need to call it with set.

  if isobject(this.GetArgument) then
    dim argumentObj : set argumentObj = this.GetArgument
  elseif isarray(this.GetArgument) then
    dim argArray : argArray = this.GetArgument
  else
    dim argVal : argVal = this.GetArgument
  end if

using this you can almost send anything and react to it.

0 Kudos
Message 3 of 4
(2,476 Views)

Thank you, that worked fine. I was confused about when to use Set and when not to. I was trying to use it to assign to a normal variable rather than an object and the help files only have an example of using GetArgument when passing an object.

 

Your reply has prompted a few questions though:

 

1. In the past I've seen code using Dialog.GetArgument but your example (and the help files) use This.GetArgument. I've tried both in the example we're discussing here and they both work. The only difference I can see is the colour that DIAdem assigns to the text - the former is brown for objects and the latter is black for text. What's the difference between them?

2. You have also used brackets after GetArgument. What's the significance of them?

3. In your helpful piece of code at the end for detecting what's passed to SUD, the last two result in the same statement (= this.GetArgument). I assume you were just highlighting the different things that can be passed to SUD and so they don't need to be separated out?

 

Many thanks again for your help.

 

Simon.

 

0 Kudos
Message 4 of 4
(2,452 Views)