PDA

Click to See Complete Forum and Search --> : Search Textbox help


Noman
Jan 22nd, 2000, 12:41 AM
Alright - I have tried everything in here. I am trying to highlight certain tex in a textbox. I already have the code to open, a file to the textbox and I know how to see if the string is in a textbox. I am using Instr(LCase(Text1.text)), LCase(X)) to find the text and tell me if it's there bu now I need to highlight the text. I would also like to know how to find the NEXT match in the textbox if you guys could help me with that. Thanks a lot guys/gals


------------------
Noman

Jan 22nd, 2000, 01:09 AM
to highlight text....


text1.selstart = (instr()...)
text1.sellength = 10 'or whatever the length of the word is.


to do the equivalent of Next, all you need to do is run the Instr() function again but use (selstart + 1) as the start point!


------------------

Wossname,
Email me: wossnamex@talk21.com :)

JeffSM
Jan 22nd, 2000, 02:00 AM
Here is the code that I'm sending you:

Option Explicit

Const pSTART = 1

Dim nLastStop As Long

Private Sub cmdNext_Click()

Dim cFind As String
cFind = UCase$(txtFind.Text)

Dim cText As String
cText = UCase$(Text1.Text) 'If cache variables your program became faster

Dim nPos As Long

On Error Resume Next
If nLastStop >= Len(cText) Then
MsgBox "No more text to find!", vbInformation
Exit Sub
End If

nPos = InStr(nLastStop, cText, cFind)

Text1.SelStart = nPos - 1
Text1.SelLength = Len(cFind)
'Text1.SelText = Mid$(cText, nPos, Len(cFind))

nLastStop = nPos + Len(cFind)

End Sub

Private Sub Form_Load()

'YOU MUST SET THIS PROPERTY TO TRUE
'IN DESING MODE IN ORDER TO WORKS.

txtFind.text = "HOME"

'Text1.HideSelection = False
Text1.Text = "Jefferson is at home." & vbCrLf & _
"Jefferson is at home." & vbCrLf & _
"Jefferson is at home." & vbCrLf & _
"Jefferson is at home." & vbCrLf & _
"Jefferson is at home." & vbCrLf & _
"Jefferson is at home." & vbCrLf & _
"Jefferson is at home." & vbCrLf & _
"Jefferson is at home." & vbCrLf & _
"Jefferson is at home." & vbCrLf & _
"Jefferson is at home." & vbCrLf & _
"Jefferson is at home."
nLastStop = pSTART
End Sub

Private Sub txtFind_Change()
'This clear and make find from begin!
nLastStop = pSTART
End Sub

Boa sorte,
Jefferson

[This message has been edited by JeffSM (edited 01-22-2000).]