LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Comparing Integer Strings Error

I am working with LabVIEW 7.1  I am having difficulty using the output of a motion controller that I am working on developing code to control.  The problem boils down to the attached code where I get unexpected results of the boolean indicator for a simple comarison of two desimal strings.  Why does the string comparison not work in the same manner as the numeric comparison would?  The comand/response pair that I am trying to process look like this:

COMMAND
MG "TEST"

RESPONSE
TEST
:

This is working through ActiveX so I am using the controllers 'container' and appropriate comands (I hope!)  Thanks in advance.
0 Kudos
Message 1 of 4
(2,447 Views)

John:

The behaviour exibited in the example you posted can be explained from this in LV help:

Comparing Strings

Comparison functions compare strings according to the values of the ASCII character codes. The Comparison functions compare strings one element at a time starting with the 0th element until they encounter an inequality or until one string ends. The longer string is greater than the shorter string.

 

~~~~~~~~~~~~~~~~~~~~~~~~~~
"It’s the questions that drive us.”
~~~~~~~~~~~~~~~~~~~~~~~~~~
0 Kudos
Message 2 of 4
(2,435 Views)
Thanks for the response.  That explains why I am unable to compare the two strings and get the same result as using numbers.  The more pertinent question I am interested in though is how can I format the output of my Active X container:

TEST
:

so that I am able to logically identify it.  Ideally so I can say does this string text (TEST) match what's coming out of the device?  Worst case I could work on developing a numeric code system that I force the motion controller to respond with so that I can cut all the formatting then transfer the output to numeric so that I can work with it.  Any suggestions would be very helpful.  Thanks.l
0 Kudos
Message 3 of 4
(2,430 Views)
The same thing happens when doing a sort in DOS/Windows applications. If you had a column of text in Excel with the values 1,2,3,4,5,6,7,8,9,10 in the rows and did a sort, you end up with 1,10,2,3,4,5,6,7,8,9. In your example, the first time the Booleans goes true is when the iteration count is equal to 5. The string "5" is equal to 0x35 in ANSI and the string 42 is 0x34 32. Because the first character 0x35 is greater than the first character 0x34 the comparison is true. One way to make things work is to force the numbers to use the same number of digits. You can use the Format Into String with a format specifier of %02d to convert the number to use a minimum field width of two and pad with zeroes.
0 Kudos
Message 4 of 4
(2,427 Views)