[RESOLVED] Search for a text in a string
All this string stuff is giving me a headache!! :confused:
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.
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
Re: Search for a text in a string
:wave:
VB Code:
Private Sub cmdSearch_Click()
found = 0
start = 1
For i = start To Len(txtString)
flag = InStr(start, txtWord, txtString)
If flag = 0 Then Exit For
If flag <> 0 Then
start = flag + 1
flag = 0
found = found + 1
End If
Next i
MsgBox "Your query - " & txtWord & " - was found " & found & " times."
End Sub
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.
Re: Search for a text in a string
Re: Search for a text in a string
thanks guys, got it working. :thumb: