DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing Global Variables to User Commands

Hello

 

I have a script defined as a user command which evaluates a cell value in a table and changes the color of the cell font based on the cell value.

 

I am essentially building a requirements user command script.

 

I was wondering if the values of global variables can be read by user command scripts? 

The idea would be my main execution script has a global variable defining the test sample variant and the requirements user command script would evaluate the results specific to the sample variant type.

 

Thanks

Tim
0 Kudos
Message 1 of 10
(5,600 Views)

Hi Smoothdurban,

 

I have looked at the following help document which has some details of the Global Variables on DIAdem, and it also has a note that says you cannot transfer global variables to a Function or to a ByRef Sub procedure. So from my understanding as long as you are not calling the variable from none of those you should be able to access the variable with no problem.

 

Hope this helps you!

Regards,

Sil.VI
0 Kudos
Message 2 of 10
(5,557 Views)

I am still a little unclear

 

currently I have a declaired global variable in my main script

GlobalDim "testVar"

and set it to some value

 

testVar = "pass"

The following registered user command does not evaulate the global the condition "If testVar = "pass""

 

 

Sub Test19(Context, Cell)
If testVar = "pass" Then 
  
 If Context.Row = 1 OR Context.Row = 2 Then
        If Cell.Value > 0.1 Then 
        Cell.Font.Color.SetRGBColor(RGB(0, 255, 0))
        Else
        Cell.Font.Color.SetRGBColor(RGB(255, 0, 0))
        End IF
   End If

End If
End Sub

 

 

Tim
0 Kudos
Message 3 of 10
(5,545 Views)

Hi Tim,

 

That really should work.  Care to send me your code and test instructions?

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 4 of 10
(5,536 Views)

Hey Brad

 

The code I have previously used as a demonstration does not illustrate the problem I am having so I will try to elaborate. 

 

I have one user command script that is trying to redraw cells in table 1 on page A and table 2 of page B

The main script changes the  global variable "testVar" to distinguish which table I want to redraw. 

 

The main script which sets testVar to "pass" and then references a column in table 1 on page A

 

o2DTableColumnChannel.Settings.OnDrawingCell = "Test19"

 

 

The main script then sets testVar to "fail" references a different column in table 2 of page B  

 

 

o2DTableColumnChannel.Settings.OnDrawingCell = "Test19"

 

 

Sub Test19(Context, Cell)
 
 If Context.Row = 1 OR Context.Row = 2 Then
        If Cell.Value > 0.1 Then 
        Cell.Font.Color.SetRGBColor(RGB(0, 255, 0))
        Else
        Cell.Font.Color.SetRGBColor(RGB(255, 0, 0))
        End IF
       If testVar = "pass" Then    
              Cell.Value = Cell.Value &"  [35 +/-0.75]"
       End If
End If


End Sub

The expect results would be as follows assuming the cell values for rows 1 & 2 were  =0.05 & 0.15

 

Rows 1 & 2 in Table 1 on Page A

0.05 [35 +/-0.75]

0.15 [35 +/- 0.75]

Rows 1 & 2 in Table 2 on Page B

0.5

0.15

 

The result I am getting is shown below

Rows 1 & 2 in Table 1 on Page A

0.05 [35 +/-0.75]

0.15 [35 +/- 0.75]

Rows 1 & 2 in Table 2 on Page B

0.5

0.15

Tim
0 Kudos
Message 5 of 10
(5,514 Views)

This has reared its ugly head again.  

I need to be able to pass global variable to a use command

Any Ideas?

Tim
0 Kudos
Message 6 of 10
(4,111 Views)

Man

 

Here we are again.  This would save a lot of redundancy if I could get some help on this.  

Tim
0 Kudos
Message 7 of 10
(3,453 Views)

Hey Tim,

 

I apologize for leaving this Discussion Forum request untended for so long-- that's embarrassing.  Feel free to nudge me directly with an email if that happens again (brad.turpin@ni.com).

 

Let's start by separating your stated question (UserCommands referencing global variables) from your desired implementation (coloring table cells on refresh).  I'm willing to get into the implementation side, but I think it's important for us and anyone else who looks at this thread to be clear about the general question.  I fully expected there to be an issue passing the global variable into any subroutine or function, including a UserCommand, but when I tried it... it worked perfectly.  I tried in DIAdem 2021, DIAdem 2019 and even DIAdem 2015 (64bit), but it worked each time.  I did expect the UserCommand could read a global variable just fine, and that indeed occurred in all those DIAdem versions as well.

 

So my first request is that you try these 3 scripts I'm attaching in your DIAdem and verify that the core question of passing and reading global variables in a generic UserCommand is resolved with a resounding yes.  Then please tell me what DIAdem version you're using.  Once those two items are out of the way, we can take a look at your implementation for table cell coloring.

 

You probably know this, and the code snippets you posted show no issue there, but just to make sure... string comparisons in VBScript are case-sensitive.  So if your global variable had the value "Pass" or "PASS", and your UserCommand was checking against "pass", then that IF THEN statement would evaluate to FALSE.

 

I also noticed that whenever I edited the UserCommand script file and saved it, my global variable was un-declared.  That also caused my UserCommand to output nothing until I ran the variable declaring and assigning script again.

 

Talk more soon,

Brad Turpin

Principal Technical Support Engineer
NI

0 Kudos
Message 8 of 10
(3,440 Views)

Hey Brad

 

Thanks for getting back to me.

 

I have attached a couple of files which I think will help illustrate the problem I having.

 

Perhaps I am not using the global variable correctly.

 

There are three files.

 

One report file

 

My main run script and the user command file

 

The user command file has two functions "EvaluateCells" and "EvaluateCellsPassGlobal"

 

The first function has the pass fail criteria hard coded in.

 

The second function I am trying to pass the "pass/fail" criteria via a global variable "passValues"  which is declared in the "RunScript.VBS"

 

Based on the output the user command is not getting the global variable declared in the RunScript.VBS

 

 

Tim
0 Kudos
Message 9 of 10
(3,431 Views)

Um, Tim,

 

Did you look at the 3 scripts I sent you and try them out at all?  I was hoping to get your results from that simple case before we forged ahead and looked at calling a UserCommand during the REPORT object refresh event.

 

Brad Turpin

Principal Technical Support Engineer

NI

0 Kudos
Message 10 of 10
(3,397 Views)