Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read textfile and change colour if "hello there" apears

Status
Not open for further replies.

Madz

Technical User
Jan 31, 2001
33
0
0
SE
I want to read a textfile and change the color of the text if; for example "hello there" apears then I want to change "hello there" to red in the textbox. Is this possible?

The next line should return to black text.

thanks in advance!

/mats
 
Yes, it's possible, but not with the textbox.

You will have to use the RichTextBox Control.

Code:
Private Sub HilightText(ByVal sText as String)
  '//sText will contain the textfile's contents
  Dim iStart as Integer
  Dim iEnd as Integer
  
  Richtextbox1.Text = sText

  iStart = 1
  iEnd = 1
  '//Loop through the text and find all instances of "Hello there!"
  While iStart > 0
    iStart = InStr(iEnd, sText, "Hello there!")
    iEnd = iStart + Len("Hello there!")
    
    '//Change the color of "Hello there!"
    Richtextbox1.SelStart = iStart
    Richtextbox1.SelLength = Len("Hello there!")
    Richtextbox1.SelColor = RGB(255, 0, 0) '//or vbRed or &H0000FF&
  Wend
End Sub

'//To use it
'--Open file
'--Read file contents
HilightText FileContents
_________________
Bixarrio
e = m * (c ^ 2)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top