search a string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jarremw
    New Member
    • Jan 2008
    • 50

    search a string

    hello all,
    this seems so simple but i just cant get it, i am trying to search a textbox for the letters "sw" if they are not there than i want a messagebox to show, simple right? well not for me....any ideas?

    thanks...
  • Robbie
    New Member
    • Mar 2007
    • 180

    #2
    Use the InStr() function. It does exactly what you want - it tells you if (and at what position) a string exists within a (larger) string.

    You use it like this:
    InStr(StartPos, LargeString, StringToFind)

    Give 1 as the StartPos for it to search from the begining of the large string. You can use larger numbers to get it to search from mid-way through the large string (to stop it finding things near the start). InStr() gives back the number of characters into LargeString which the first StringToFind appears at (starting searching from StartPos).

    If no string is found, InStr() gives 0. So, you could see if InStr(1, YourString, WhatYouWantToFi nd) gives back 0, and if so, the little string doesn't exist, so you can show the message.

    Comment

    • jarremw
      New Member
      • Jan 2008
      • 50

      #3
      worked perfectly! thanks for the quick reply!

      Comment

      • Robbie
        New Member
        • Mar 2007
        • 180

        #4
        Originally posted by jarremw
        worked perfectly! thanks for the quick reply!
        No problem - I'm glad it's working now. =)
        Actually, I didn't first realize how recent your post was when I replied. ><

        Comment

        Working...