Host Engineering Forum
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
September 25, 2017, 11:49:19 am


Login with username, password and session length


Pages: [1]
  Print  
Author Topic: String Compare  (Read 125 times)
PLCGuy
Internal Dev
****
Posts: 506



« on: September 13, 2017, 05:39:50 am »

I am not understanding the string compare at all. I can not get the the equal bit to turn on when the same string is in each. This is what I am thinking. SS0 is 64 characters and the cast I built is ProductName0 is 12 characters. I uss SS0 on my HMI. What ever is put in SS0 by the user is compared to ProductName[v0]. I have not tried it yet but either I create another cast to replace SS0 on the HMI which will be 12 Characters or somehow use trim to shrink down SS0 before comparing. I am thinking the extra spacing is causing my issue. Is this correct? For compare to work the strings need to be the same character allotment?  If I use all SS strings in my experiment it works correctly every time. As soon as i mix ss strings with my cast strings it does not work.
Logged
franji1
Bit Weenie
Host Moderator
*****
Posts: 2144



WWW
« Reply #1 on: September 13, 2017, 06:24:20 am »

Look at both in Data View and look at then in Quoted format or one of the Hex formats.  That will help you see if there are any issues.

You probably need to check Ignore Case in the STRCMP box.

Also, since you are using arrays on ProductName, you are probably using FOR/NEXT.  Make sure you use BREAK being driven by the EqualTo bit to break out of the loop.  Then V0 will equal the found index after the NEXT if the EqualTo bit is ON.  If it is OFF after the NEXT, then it did not find a match.
Logged

plcnut
Hero Member
*****
Posts: 710



« Reply #2 on: September 13, 2017, 06:49:54 am »

The .MaxLength does not effect the STRCMP.
You do want to make sure that you are not using the 'Rising edge' in the STRCMP if it is in a loop.
A screenshot of the code may be helpful.
Logged

Circumstances don't determine who we are, they only reveal it.

~Jason Wolthuis
PLCGuy
Internal Dev
****
Posts: 506



« Reply #3 on: September 13, 2017, 10:14:59 am »

I think I got it. I am not using next or any loops. I had to go through the whole program and un-click both boxes where I was using STRPRINT. It would work okay when I used any SSx not being used in the program but did not work properly when I used the SSx I had in the program itself. I was ignoring caps, but had the space box checked. Once I removed both check boxes, it seems to be working. What is the option "Insert space after each term" doing? After reading what you both replied, that caused me to go through the whole program and see what was checked. Thanks
Logged
franji1
Bit Weenie
Host Moderator
*****
Posts: 2144



WWW
« Reply #4 on: September 13, 2017, 10:29:39 am »

If you do STRPRINT V0 V1 V2, it will add a space after every value.  If you had it UNchecked, you would manually have to put the space in between as string literals " ".

Note that it adds a space AFTER EACH/EVERY element/literal/function in the STRPRINT, not just BETWEEN them.  If you just wanted them BETWEEN (and not after the LAST one), go ahead and check it, but then use STRTRIM box to trim any trailing whitespace.
Logged

PLCGuy
Internal Dev
****
Posts: 506



« Reply #5 on: September 13, 2017, 11:18:24 am »

Thank you.
Apparently when I had some of the STRPRINT options different from some others in the program mulipulating the strings, string complare did not like it. Some boxes I had add spaces clicked some I did not. I did not think spaces would effect how it works. Not sure this is the behavior you intended with spaces. As my last resort I was going to use the STRTRIM, but now I do not need to. With all the STRPRINT options uncheck, it is working. I might go back and check them to see what happens. I am believing to think all STRPRINT options need to be set the same. At least the ones sharing the same strings. It looked like some were adding spaces and some were not so when I did the compare, it was not working the way I wanted it to.
Logged
BobO
Host Moderator
*****
Posts: 3627


Yes Pinky, Do-more will control the world!


« Reply #6 on: September 13, 2017, 11:21:37 am »

Thank you.
Apparently when I had some of the STRPRINT options different from some others in the program mulipulating the strings, string complare did not like it. Some boxes I had add spaces clicked some I did not. I did not think spaces would effect how it works. Not sure this is the behavior you intended with spaces. As my last resort I was going to use the STRTRIM, but now I do not need to. With all the STRPRINT options uncheck, it is working. I might go back and check them to see what happens. I am believing to think all STRPRINT options need to be set the same. At least the ones sharing the same strings. It looked like some were adding spaces and some were not so when I did the compare, it was not working the way I wanted it to.

Spaces are as significant as any other character. I suppose we could add an option to ignore leading and trailing whitespace, but it is working exactly as intended.
Logged

"We would rather apologize to 20% for what we chose not to do, than to apologize to 100% for what we did poorly." -BobO
plcnut
Hero Member
*****
Posts: 710



« Reply #7 on: September 13, 2017, 02:25:50 pm »

I never leave the 'spaces' checkbox on. If I want a space, then I add it myself.
Logged

Circumstances don't determine who we are, they only reveal it.

~Jason Wolthuis
BobO
Host Moderator
*****
Posts: 3627


Yes Pinky, Do-more will control the world!


« Reply #8 on: September 13, 2017, 02:42:36 pm »

I never leave the 'spaces' checkbox on. If I want a space, then I add it myself.

And in retrospect, that probably should have been the default. This comes up a lot.
Logged

"We would rather apologize to 20% for what we chose not to do, than to apologize to 100% for what we did poorly." -BobO
PLCGuy
Internal Dev
****
Posts: 506



« Reply #9 on: September 14, 2017, 10:54:02 am »

thanks for all the info. So spaces are significant. That was the problem all along then. It is working perfectly.
Logged
franji1
Bit Weenie
Host Moderator
*****
Posts: 2144



WWW
« Reply #10 on: September 14, 2017, 10:58:18 am »

thanks for all the info. So spaces are significant. That was the problem all along then. It is working perfectly.
Quoted format in Data View is your friend (can't see trailing spaces in ASCII format).

We are working on letting you change the Status format for STRINGs in Ladder View.  It is fixed at ASCII.  Being able to see it in Quoted format in Ladder View on the STRCMP instruction would have helped identify the issue in the STRPRINT.
Logged

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM