Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Friday, June 20, 2025 
 
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!
 Architect Forums - SalesLogix Scripting & Customization
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.
Forums RSS Feed


 Back to Forum List | Back to SalesLogix Scripting & Customization | New ThreadView:  Search:  
 Author  Thread: Instr problem
Steve Knowles
Posts: 657
Top 10 forum poster: 657 posts
 
Instr problemYour last visit to this thread was on 1/1/1970 12:00:00 AM
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
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: Instr problemYour last visit to this thread was on 1/1/1970 12:00:00 AM
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?
[Reply][Quote]
Steve Knowles
Posts: 657
Top 10 forum poster: 657 posts
 
Re: Instr problemYour last visit to this thread was on 1/1/1970 12:00:00 AM
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
[Reply][Quote]
Steve Knowles
Posts: 657
Top 10 forum poster: 657 posts
 
Re: Instr problemYour last visit to this thread was on 1/1/1970 12:00:00 AM
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
[Reply][Quote]
Steve Knowles
Posts: 657
Top 10 forum poster: 657 posts
 
Re: Instr problemYour last visit to this thread was on 1/1/1970 12:00:00 AM
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.
[Reply][Quote]
Stephen Redmond
Posts: 190
 
Re: Instr problemYour last visit to this thread was on 1/1/1970 12:00:00 AM
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
[Reply][Quote]
Steve Knowles
Posts: 657
Top 10 forum poster: 657 posts
 
Re: Instr problemYour last visit to this thread was on 1/1/1970 12:00:00 AM
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
[Reply][Quote]
 Page 1 of 1 
  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!
 

 
 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2025 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 6/20/2025 4:37:18 PM