NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Precondition string compare problem

Solved!
Go to solution
Highlighted

I can't believe I have to ask about this, but I am so confused why it doesn't work. It should be simple.

 

FileGlobal.ProductID = "07"

This is a string.

 

Why then, does this expression evaluate to True?

 

FileGlobals.ProductID == "01" || "02"

 

In order to debug, I made a Pass/fail step with it's Data Source expression set to:

(FileGlobals.ProductID == "01" || "02") ? (Step.Result.PassFail = True) : (Step.Result.PassFail = False)

This also evaluates to True.

 

I want it to be True for "01" or "02", but not for "03" etc...

 

 

0 Kudos
Message 1 of 6
(216 Views)
Highlighted
Solution
Accepted by topic author DrOnline82

I found this in the expression builder for "logical or":

String operands are converted to True if the text [...] contains the representation of a non-zero number, False otherwise.

 

This seems like odd behavior to me, but I'll just have to work around it. I didn't know this.

 

I'm trying to use StrComp(), but I can't make heads or tails of the documentation here:

 

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

"A number less than 0 if the first string is less than the second. A number greater than 0 if the first string is greater than the second. 0 if the strings are equal."

 

What does it mean for a string to be great than another string? Mathematically?

StrComp("Buddy","Budgy") evaluates to -1

StrComp("Budgy","Buddy") evaluates to 1

I don't understand the logic here.

 

If anybody can shed some light on this for me, it would be appreciated! I've decided to solve it in LabVIEW instead. What I want is a TestStand expression like this: StringsMatch("01","01") evaluating to True (boolean)

0 Kudos
Message 2 of 6
(204 Views)
Highlighted
Solution
Accepted by topic author DrOnline82

FileGlobals.ProductID == "01" || FileGlobals.ProductID == "02"

🙂 

 

The problem with "FileGlobals.ProductID == "01" || "02"" is that you're actually checking here if:

(FileGlobals.ProductID == "01" is TRUE) OR ("02" is TRUE)

While the first part is false (because FileGlobals.ProductID is actually "07"), the second part is true ("02" converts to boolean as TRUE) which results in TRUE as the "OR" result

 

 

Mateusz Owczarek

Certified LabVIEW Architect
Certified TestStand Architect
Message 3 of 6
(178 Views)
Highlighted

Holy cow I spent a lot of time on this. And it was that simple... Thanks Mateusz!!

0 Kudos
Message 4 of 6
(174 Views)
Highlighted

Glad I could help 🙂 

Mateusz Owczarek

Certified LabVIEW Architect
Certified TestStand Architect
0 Kudos
Message 5 of 6
(169 Views)
Highlighted

Yes, I see you added more to your answer. After you posted your answer I understood the same thing as you described it.

0 Kudos
Message 6 of 6
(155 Views)