NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

What's wrong with this post-expression? I keep getting an error.

I am trying to modify a post-expression on a pass/fail step.  Below is what I started with that works.

This worked:

Locals.Main_Report += "\n\t" + str(Locals.FAULTCODE) + "\t\t\t\t" + str(Locals.J1939_SPN) + "\t\t " + str(Locals.J1939_FMI) + "\t\t\t" + str(Locals.Match_Found) , (Locals.Match_Found == 0)?Parameters.TestResult = False : ""

I decided that I needed make a decision based on Match_Found and J1939_SPN, so I added a conditional statement which is shown in red below.  Match_Found is a boolean and J1939_SPN is a number.  I get an error stating specified value doesn't have the correct type.  What is odd, is if I change Locals.Match_Found == 0 to Locals.Match_Found == 1, there isn't an expression error.  This won't work though, since I need to check for Match_Found == 0.

Locals.Main_Report += "\n\t" + str(Locals.FAULTCODE) + "\t\t\t\t" + str(Locals.J1939_SPN) + "\t\t " + str(Locals.J1939_FMI) + "\t\t\t" + (Locals.Match_Found == 0 && Locals.J1939_SPN == 0)?"SPN=0, N/A" : str(Locals.Match_Found) , (Locals.Match_Found == 0)?Parameters.TestResult = False : ""

Does anything obvious look wrong with my expression?

thanks

Tim

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

I don't see anything obvious but you may want to break it up and test any comparisions seperatly or assignments seperatly if you can.

I do have a suggestion, the conditional operator usage is: booleanValue ? <expr1> : <expr2> , so if Match_Found is a boolean you don't have to compare it to a value, if you do you should probably compare it to a boolean or boolean constant (True/False not 0 or 1).

What is the data type for Parameters.TestResult? Is it boolean?

 

0 Kudos
Message 2 of 5
(3,232 Views)
Parameters.TestResult is a boolean.  Yes, I agree I should be consistent in using True/False for all booleans.  I don't think however that this is causing the expression to fail since I tried changing all booleans to True/False instead of 1/0.
 
-Tim
0 Kudos
Message 3 of 5
(3,229 Views)
Give this a try:

Locals.Main_Report += "\n\t" + str(Locals.FAULTCODE) + "\t\t\t\t" + str(Locals.J1939_SPN) + "\t\t " + str(Locals.J1939_FMI) + "\t\t\t" +  ((Locals.Match_Found == 0 && Locals.J1939_SPN == 0)?"SPN=0, N/A" : str(Locals.Match_Found)) , (Locals.Match_Found == 0)?Parameters.TestResult = False : ""

 

I just added an extra set of brackets in red...

I think it was evaluating the boolean part of your conditional and trying to append it to the string, adding the brackets makes the result of the conditional happen first.

Message Edited by paulmw on 07-26-2007 10:31 AM

0 Kudos
Message 4 of 5
(3,223 Views)
I figured it out.  Silly mistake.  locals.J1939_SPN is a string, not a number.
thanks.
0 Kudos
Message 5 of 5
(3,219 Views)