Results 1 to 6 of 6

Thread: [RESOLVED] Search for a text in a string

  1. #1

    Thread Starter
    Addicted Member oldmcgroin's Avatar
    Join Date
    Jul 2005
    Location
    Manchester, UK
    Posts
    182

    Resolved [RESOLVED] Search for a text in a string

    All this string stuff is giving me a headache!!

    Can you guys help me out again. i'm basically trying to write a program that can search for word in a string. I enter some text into one text box and then enter the word to be searched into another text box and then i press find and i want a message box to come up saying "word found" or "word not found."
    Also if possible can you tell me how to count how many times the word has been used.

    If possible can you make the code as simple and beginner friendly as possible so i can understand it.

    I've been struggling a bit lately, especially with the stings. Can anyone point me in the direction of any good websites or books that give good thorough tutorials about these kind of basics. I'm a bit embarrassed about always coming on here and asking you guys all these questions. I'm not freeloading or anything i am genuinly stuck.
    The book i'm using has good questions but the examples and tutorials aren't in depth enough. They just skim the surface.

    Thanks for your help.

  2. #2
    Frenzied Member yrwyddfa's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    1,253

    Re: Search for a text in a string

    http://www.vbforums.com/showthread.p...13#post2140013

    Starts with counting the number of times a string occurs within another string. I think I'm right in suggesting that it starts with simple stuff, and eventually gets to some real 'how fast can we really get this thing to go' stuff

    Hope it helps

    M
    "As far as the laws of mathematics refer to reality, they are not certain; and as far as they are certain, they do not refer to reality." - Albert Einstein

    It's turtles! And it's all the way down

  3. #3
    Hyperactive Member Datacide's Avatar
    Join Date
    Jun 2005
    Posts
    309

    Re: Search for a text in a string



    VB Code:
    1. Private Sub cmdSearch_Click()
    2.  
    3.   found = 0
    4.   start = 1
    5.   For i = start To Len(txtString)
    6.     flag = InStr(start, txtWord, txtString)
    7.     If flag = 0 Then Exit For
    8.     If flag <> 0 Then
    9.       start = flag + 1
    10.       flag = 0
    11.       found = found + 1
    12.     End If
    13.   Next i
    14.  
    15.   MsgBox "Your query - " & txtWord & " - was found " & found & " times."
    16.  
    17. End Sub
    PHP in your FACE!

  4. #4

    Thread Starter
    Addicted Member oldmcgroin's Avatar
    Join Date
    Jul 2005
    Location
    Manchester, UK
    Posts
    182

    Re: Search for a text in a string

    thanks datacide. thats exactly what i was looking for. it keeps giving me a result of 0 though whenever i search for a word.

  5. #5
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Search for a text in a string

    For all your string needs have a look here

    http://www.vbforums.com/showthread.php?t=316508

  6. #6

    Thread Starter
    Addicted Member oldmcgroin's Avatar
    Join Date
    Jul 2005
    Location
    Manchester, UK
    Posts
    182

    Re: Search for a text in a string

    thanks guys, got it working.

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