Click to See Complete Forum and Search --> : Please Help


AndyK
October 28th, 1999, 05:47 PM
How can I by pressing command button select (highlight) specific word in text1 ?????

santulan
October 28th, 1999, 11:16 PM
AndyK,

What I understood from your question is that you want to high light a specific word in a text box. If that is the case, I am giving you the code.
To test the code, I have drawn a text box and a comamnd button. I type a long text in text box and then click the command button and through an input box, I try to find a word typed in input box in text box. If the word is found, computer high lights the word in text box. You can modify, as per your requirements -

private Sub Command1_Click()
Dim Search, Where ' Declare variables.
' get search string from user.
Text1.SetFocus
Search = InputBox("Enter text to be found:")
Where = InStr(Text1.Text, Search) ' Find string in text.
If Where then ' If found,
Text1.SelStart = Where - 1 ' set selection start and
Text1.SelLength = len(Search) ' set selection length.
else
MsgBox "string not found." ' Notify user.
End If

End Sub




I hope this will solve the problem. In case of problem, Please let me know.

Santulan