Hi,

I'm manage how to find word in textbox.
In textbox : "How i can be a good programer? How i achieve that?"
If i want to search "How" then it should return 2 How words in text.

Please Help.
Thank You.

Recommended Answers

See if this helps :
[CODE]
Dim i, Count As Integer

Count = 0

i = InStr(i + 1, Text1.Text, "How")
If i = 0 Then
MsgBox 0
Exit Sub
End If

Do While i > 0
i = InStr(i + 1, Text1.Text, "How")
Count = Count + 1
Loop

Jump to Post

All 6 Replies

How far you doing this?
Post the code that you've been work.

This what i have so far :

Dim str As String
Dim i, temp, Count As Integer
Count = 0

While temp > 0
    temp = InStr(1, Text1.Text, "How")
    Count = Count + 1
Wend
MsgBox Count

But the result is wrong.

See if this helps :

Dim i, Count As Integer

Count = 0

i = InStr(i + 1, Text1.Text, "How")
If i = 0 Then
    MsgBox 0
    Exit Sub
End If

Do While i > 0
    i = InStr(i + 1, Text1.Text, "How")
    Count = Count + 1
Loop

MsgBox Count
commented: Thanks +2
commented: Nice code +2

Thanks jx..it worked fine.

You're Welcome.
Don't Forget to mark this thread as solved.
Happy Coding ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.