How do we do text searches on a multitextbox ?

blumonde

Well-known member
Joined
Jul 26, 2005
Messages
68
Programming Experience
Beginner
Gentlemen,

I use a multitextbox to display some document. I need to find a way to search a word in the document. I checked its methods. I didn't see anything I could use.

Please help.

Thanks.

blumonde
 
Last edited:
If OpenFileDialog1.ShowDialog = DialogResult.OK Then

Dim objfilestream As New System.IO.FileStream(OpenFileDialog1.FileName, IO.FileMode.Open, IO.FileAccess.ReadWrite)

Dim objreader As New System.IO.StreamReader(objfilestream)

Dim str, getstr As String

str = TextBox1.Text 'the word u want to find in the document

getstr = objreader.ReadLine

While Not getstr Is Nothing

getstr = objreader.ReadLine

If getstr.StartsWith(str) Then

MessageBox.Show("word found")

Exit While

Else

End If

End While

objreader.Close()

objfilestream.Close()

End If

 
nakracreative said:
If OpenFileDialog1.ShowDialog = DialogResult.OK Then

Dim objfilestream AsNew System.IO.FileStream(OpenFileDialog1.FileName, IO.FileMode.Open, IO.FileAccess.ReadWrite)

Dim objreader AsNew System.IO.StreamReader(objfilestream)

Dim str, getstr AsString

str = TextBox1.Text 'the word u want to find in the document

getstr = objreader.ReadLine

WhileNot getstr IsNothing

getstr = objreader.ReadLine

If getstr.StartsWith(str) Then

MessageBox.Show("word found")

ExitWhile

Else

EndIf

EndWhile

objreader.Close()

objfilestream.Close()

EndIf



Hi nakracreative,

Thanks for the code. It will help me get it done! I would like it to highlight the word I search while the document is open in front of me. Is it possible ? I would place a button called "Find" on the multitextbox window. So when I open the document and need to find a word, I click on "Find", enter the word, and it will search and highlight the word in the document. I can use your code above to make it work that way ?

Cheers,

blumonde
 
Back
Top