News:

  • April 19, 2024, 12:43:36 AM

Login with username, password and session length

Author Topic: String Compare  (Read 3402 times)

PLCGuy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 677
String Compare
« on: September 13, 2017, 06: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.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3658
    • Host Engineering
Re: String Compare
« Reply #1 on: September 13, 2017, 07: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.

plcnut

  • Hero Member
  • *****
  • Posts: 803
    • premiersi.com
Re: String Compare
« Reply #2 on: September 13, 2017, 07: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.
Circumstances don't determine who we are, they only reveal it.

~Jason Wolthuis
Premier Systems Integration, LLC
http://premiersi.com

PLCGuy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 677
Re: String Compare
« Reply #3 on: September 13, 2017, 11: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

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3658
    • Host Engineering
Re: String Compare
« Reply #4 on: September 13, 2017, 11: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.

PLCGuy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 677
Re: String Compare
« Reply #5 on: September 13, 2017, 12:18:24 PM »
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.

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 5984
  • Yes Pinky, Do-more will control the world!
Re: String Compare
« Reply #6 on: September 13, 2017, 12:21:37 PM »
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.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

plcnut

  • Hero Member
  • *****
  • Posts: 803
    • premiersi.com
Re: String Compare
« Reply #7 on: September 13, 2017, 03:25:50 PM »
I never leave the 'spaces' checkbox on. If I want a space, then I add it myself.
Circumstances don't determine who we are, they only reveal it.

~Jason Wolthuis
Premier Systems Integration, LLC
http://premiersi.com

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 5984
  • Yes Pinky, Do-more will control the world!
Re: String Compare
« Reply #8 on: September 13, 2017, 03: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.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

PLCGuy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 677
Re: String Compare
« Reply #9 on: September 14, 2017, 11:54:02 AM »
thanks for all the info. So spaces are significant. That was the problem all along then. It is working perfectly.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3658
    • Host Engineering
Re: String Compare
« Reply #10 on: September 14, 2017, 11: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.