|
-
Sep 14th, 2005, 09:40 AM
#1
Thread Starter
Addicted Member
[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.
-
Sep 14th, 2005, 09:47 AM
#2
Frenzied Member
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
-
Sep 14th, 2005, 09:51 AM
#3
Hyperactive Member
Re: Search for a text in a string

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
-
Sep 14th, 2005, 10:23 AM
#4
Thread Starter
Addicted Member
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.
-
Sep 14th, 2005, 10:27 AM
#5
Re: Search for a text in a string
-
Sep 14th, 2005, 10:39 AM
#6
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|