12-02-2016 08:33 AM
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
12-05-2016 07:13 PM
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!
12-06-2016 05:43 AM
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
12-06-2016 09:23 AM
Hi Tim,
That really should work. Care to send me your code and test instructions?
Brad Turpin
DIAdem Product Support Engineer
National Instruments
12-07-2016 12:50 PM
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
01-07-2020 10:50 AM
This has reared its ugly head again.
I need to be able to pass global variable to a use command
Any Ideas?
05-10-2021 05:40 PM
Man
Here we are again. This would save a lot of redundancy if I could get some help on this.
05-11-2021 09:13 AM - edited 05-11-2021 09:13 AM
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
05-11-2021 12:07 PM
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
05-14-2021 04:01 PM
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