07-26-2007 09:24 AM
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
07-26-2007 09:54 AM
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?
07-26-2007 10:05 AM
07-26-2007 10:30 AM - edited 07-26-2007 10:30 AM
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
07-26-2007 10:33 AM