NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Evaluate() with and without expression

Hello,

 

I want to insert into my teststand report the messages displayed to the operator (Message Popups). To do so, I use the "Step.MessageExp" value.

Sometimes this message has to be evaluated.

Example of message expression: "Please do: "+ (
(Locals.Case == "A")? "This":
(Locals.Case == "B")? "That":
(Locals.Case == "C")? "Wathever":
"Unexpected case")
And sometimes it is just a string (eg: "Please do that")

The problem I am facing is that if I use the following post-expression, it won't work when the message is just a string because nothing has to be evaluated:

Step.Result.ReportText="The following text was displayed:" + Evaluate(Step.MessageExpr)

 

How can I solve this? 

 

Thank you!

0 Kudos
Message 1 of 10
(3,137 Views)

I can't reproduce what you are seeing, in other words, both strings and expressions work the same for me.  What version of TestStand are you using?  Also, do you have a simple example you could post that exhibits this behavior?

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
0 Kudos
Message 2 of 10
(3,083 Views)

I am using TestStand 2019 32-bits.

I wasn't able to reproduce the problem because I changed my code in the meantime. But I am still facing the same kind of problem. I brought an example here.

I want to add the picture displayed in the MessagePopup in the report by adding the following post-expression code:

Step.Result.ReportText="The following image was displayed:

" +( (Step.FileData.ShowFile )? "<IMG ALT='"+Evaluate(Step.TitleExpr)+"' src='"+ Locals.SequenceDir + "\\"+ Evaluate(Step.FileData.Path) +"' width='500px'></IMG>":"No File Displayed" )

 

When Step.FileData.Path is a "Path" and not an "Expression", Evaluate(Step.FileData.Path) won't work as I get the error in my example: Error in call to expression function 'Evaluate'. Unknown variable or property name 'cat'.

Why can't Evaluate("cat.jpg") return the string "cat.jpg"?

Even changing the Evaluate(Step.FileData.Path) by :

(Step.FileData.Source==0)?Step.FileData.Path:Evaluate(Step.FileData.Path)

doesn't seems to work.

 

I hope my example is clear enough to highlight my problem.

 

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

Step.FileData.Path is a string.  You do not need to evaluate.  In fact you cannot evaluate it unless the string is an expression string.  Hence why it is throwing an error.

 

There is a vast difference between a string and an expression string.   If you were to type Cat.jpg into an expression in TestStand you would see the exact same error.  It's because it doesn't have the quotes.  For it to be an expression you need the quotes ("Cat.jpg").  Becasue Step.FileData.Path is a string then the evaluate function is evaluating Cat.jpg without quotes.

 

Remove the evaluate method on the path and you should be good to go.

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
0 Kudos
Message 4 of 10
(3,044 Views)

Thank you for your explanation. Is there a general expression to retrieve the path of the image in the both cases, where Step.FileData.Path is:

  • A regular path, thus a String
  • A path by expression, thus an expression String

I tried using the Step.FileData.Source property as it seems like:

  • Source = 0 --> File
  • Source = 1 --> Step
  • Source = 2 --> File by expression

In my case I only consider cases "0" and "2", therefore I tried with :

(Step.FileData.Source==0)?Step.FileData.Path:Evaluate(Step.FileData.Path)

Even if during execution it seems to work as expected, TestStand Sequence Analyzer tells me there are errors in my code.
Here attached the sequence modified where Seq Analyzer fails

 

0 Kudos
Message 5 of 10
(3,027 Views)

https://zone.ni.com/reference/en-XX/help/370052W-01/tsfundamentals/infotopics/novalidation/

 

This should help eliminate the pain of the sequence analyzer.

 

Cheers,

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
0 Kudos
Message 6 of 10
(3,007 Views)

I am afraid it is still not working, maybe I am not using the #NoValidation properly?

The following expression returns an error in the sequence analyzer when Step.FileData.Path is a regular path (no expression). I tought that the NoValidation tag would prevent TestStand from evaluating what's Inside the expression?

((Step.FileData.Source==0)?Step.FileData.Path:#NoValidation(Evaluate(Step.FileData.Path)))

0 Kudos
Message 7 of 10
(2,975 Views)

#NoValidation((Step.FileData.Source==0)?Step.FileData.Path:Evaluate(Step.FileData.Path))

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
0 Kudos
Message 8 of 10
(2,960 Views)

This expression seems to work when all images are in the root directory of the sequence, but not when they are in a separate (relative) folder.

As in the example here enclosed.

0 Kudos
Message 9 of 10
(2,946 Views)

It's because you have a search directory issue.  You need to fix your search directories to include the folder where the files are.  Or use relative paths and change your expression.

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
0 Kudos
Message 10 of 10
(2,928 Views)