Results 1 to 5 of 5

Thread: Comparing an Integer in a String

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Posts
    2
    I know this is going to seem like an easy question, but I can't find the right syntax to handle it!

    I have a string...

    mystring = 10,11,12

    and I am looping through a set of numbers i = 1-20

    In the loop I compare i to mystring, and if the number in mystring is equal to i then I mark the check box as selected.

    My problem is when I say Instr(mystring,i) and i=1 (for example) it is true because there is a 1 in the string, but it's not the truth I want because it's not 10,11,or 12.

    I think I did a bad job of explaining that but if anyone has every handled this situation it would really help me out!

  2. #2
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    if your string has commas in it like that then you could do. Make sure the string starts with a comma though.

    Code:
    Instr(myString, "," & i & ",")
    Iain, thats with an i by the way!

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    If you have VB6 then use the Split fuction to break up the string into it's numbers and then compare i with the entries in the array that Split creates. If you don't have VB6 then build an array by examining the characters in the string one by one. If you need help with either approach let me know.

  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Posts
    2
    Thank You,Iain17 !! That was exactly what I needed!

  5. #5

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width