NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Unknown Variables and PropertyExists

I have a property in my step types for TestNumber... I want to use this either hard coded or programatically... so as a preexpression I put in a statement of:

PropertyExists("Locals.TestNumber")?Step.TestNumber=Locals.TestNumber:Step.TestNumber

My thoughts were... if the local sequence had a variable testnumber to use that, otherwise to use what was in the step property... this way some sequences could be programatic and others could be hard coded...

My problem is...

I'm getting an error/warning of expressions must evaluate to the expected type... and "unknown variable or property name" in regards to the locals.testnumber...

If I run it and ignore the error, it executes properly... updating the step.testnumber when locals.testnumber and using the step.testnumber otherwise... but what is causing the error?  I thought that was the purpose of the propertyexists statement to check if something is valid before using it in an expression....

0 Kudos
Message 1 of 5
(3,451 Views)

 

Put the expression in brackets eg

(PropertyExists("Locals.TestNumber"))?(Step​.TestNumber=Locals.TestNumber):Step.TestNumber

 

 

Regards
Ray Farmer
0 Kudos
Message 2 of 5
(3,450 Views)

It still gives an error regarding locals.testnumber not existing... but it shouldn't be evaluating that part of the conditional statement since the propertyexists should return a false when it doesn't exist...

0 Kudos
Message 3 of 5
(3,446 Views)

I had the following in a Statement step and no errors

 

PropertyExists ("Locals.TestNumber" ) ? (Step.Result.ReportText = Locals.TestNumber) : (Step.Result.ReportText ="No" )

 

Locals.TestNumber doesn't exist in my Sequence

 

Regards
Ray Farmer
0 Kudos
Message 4 of 5
(3,440 Views)

I figured out the problem and it was related to the TS Analyzer and rule "Expressions Must Evaluate to a value of the expected type"

If you don't have analyze before running enabled, you'll never see the error... if you run the analyze, that rule will cause an error... which isn't really an error when you consider the surrounding expressions to check if the property exists...

0 Kudos
Message 5 of 5
(3,437 Views)