6/20/2025 2:28:16 PM
|
|
slxdeveloper.com Community Forums |
|
|
|
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
Forum to discuss writing script in Architect plugins for SalesLogix & general SalesLogix customization topics (for Windows client only). View the code of conduct for posting guidelines.
|
|
|
|
Instr problem
Posted: 04 Oct 07 3:57 PM
|
I have a field that holds a comma delimited list of counties (this could not be avoided) . I have some logic that loops through the comma delimited list and looks for a match for a county in the list. County1, County2, County3 etc.
The code works fine [instr(txtCounty.text, clbCounty.Items.Item(i))] until you one county that has another couties name in it - like Harris and Harrison - so Harris will evaluate true if Harrison is in the list. Is there an easy way to remedy this? I am trying to find a way to find out if there is a comma the end of the value that getting compared in the delimited list.. any thoughts? Thanks ... 'Check counties previously selected For i = 0 to clbCounty.Items.Count- 1 'If clbCounty.Checked(i) = True then If instr(txtCounty.text, clbCounty.Items.Item(i))<>0 then clbCounty.Checked(i) = True End If Next |
|
|
|
Re: Instr problem
Posted: 04 Oct 07 4:15 PM
|
Maybe it would be easier to just split the string into an array of values?
Something like this?
Dim sCountryList Dim ar_Countries Dim i sCountryList = "USA, Spain, Iceland" ar_Countries = Split(sCountryList, ",") For i = LBound(ar_Countries) To UBound(ar_Countries) MsgBox Trim(ar_Countries(i)) Next
Make sense? |
|
|
|
Re: Instr problem
Posted: 04 Oct 07 4:19 PM
|
Ah, I smell what yer cookin'. Throw 'em in an array and compare the actual values whilst looping. Thanks Ryan |
|
|
|
Re: Instr problem
Posted: 04 Oct 07 4:47 PM
|
Ok, he who smelt it dealt it..
I am already looping through a checklistbox populated with possible counties for a given state. I tried something like this, looping through the Checklistbox counties, then looping throught the array to check values. This only checks one of the boxes each time.. plus it is pretty inefficient (although this form is rarely used). ar_Counties = Split(txtCounty.text, ",") For i = 0 to clbCounty.Items.Count- 1 For n = LBound(ar_Counties) To UBound(ar_Counties) If ucase(ar_Counties(n))= ucase(clbCounty.Items.Item(i)) then clbCounty.Checked(i) = True End If Next Next |
|
|
|
Re: Instr problem
Posted: 05 Oct 07 7:12 AM
|
I ended up appending a comma to the end of my county string and to the end of the value I am comparing from the checklistbox collection. |
|
|
|
Re: Instr problem
Posted: 06 Oct 07 5:13 AM
|
And that is a really easy and efficient way of doing it. Well done.
I have run into a similar problem before when I was comparing '|' seaparated values with a piece of text and getting hits where I shouldn't be. I went a step further than you and added a '|' to either end of both the search and list strings before using INSTR. That way, if I had a match at the end of the string it would discount it too.
You might want to consider this because you might get some hits like that - e.g. "redmond,stephen," will get hits for "redmond," and "edmond," whereas ",redmond,stephen," will not get a hit for ",edmond,"
Stephen
|
|
|
|
Re: Instr problem
Posted: 06 Oct 07 7:41 AM
|
Good call. I had added a comma to the end of the comma delimited string, but had not considered the 'edmond' syndrome. I will definately add that in to tighten up the logic. Thanks SR |
|
|
|
You can
subscribe to receive a daily forum digest in your
user profile. View the site code
of conduct for posting guidelines.
Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
|
|
|
|
|
|
|
|