|
-
Mar 26th, 2005, 08:55 AM
#22
Need-a-life Member
Re: Color coding
 Originally Posted by Tempestknight
Sure
VB Code:
Option Explicit
Private Sub HighlightText(sKeyword As String, iColour As Long)
Dim nStart As Integer, sPrevChar As String, sNextChar As String
nStart = InStr(1, UCase(RichTextBox1.Text), sKeyword, vbTextCompare)
Do While nStart <> 0
If nStart > 1 Then
sPrevChar = Mid$(RichTextBox1.Text, nStart - 1, 1)
Else
sPrevChar = " "
End If
If Len(RichTextBox1.Text) >= nStart + Len(sKeyword) Then
sNextChar = Mid$(RichTextBox1.Text, nStart + Len(sKeyword), 1)
Else
sNextChar = " "
End If
If (sPrevChar = Chr(32) Or sPrevChar = Chr(13) Or _
sPrevChar = Chr(10) Or sPrevChar = Chr(9)) And _
(sNextChar = Chr(32) Or sNextChar = Chr(13) Or _
sNextChar = Chr(10) Or sNextChar = Chr(9) Or sNextChar = ".") Then
With RichTextBox1
.SelStart = nStart - 1
.SelLength = Len(sKeyword)
.SelColor = iColour
.SelText = sKeyword
.SelStart = Len(RichTextBox1.Text)
.SelColor = iColour
End With
End If
nStart = InStr(nStart + Len(sKeyword), UCase(RichTextBox1.Text), sKeyword, vbTextCompare)
Loop
End Sub
Private Sub RichTextBox1_Change()
With RichTextBox1
.SelStart = 0
.SelColor = vbBlack
.SelStart = Len(.Text)
End With
' Add more custom words here
HighlightText "END", vbRed
HighlightText "GOTO", vbYellow
HighlightText "IF", vbBlue
End Sub
thats what i got i want it to go back to black after i type say GOTO or IF or END...
It does a little flicker... but can't think of another solution without messing around too much with the code.
VB Code:
Option Explicit
Private Sub UnHighlightText(iColour As Long)
Dim iPos As Long
With RichTextBox1
iPos = .SelStart
.SelStart = 0
.SelLength = Len(.Text)
.SelColor = iColour
.SelStart = iPos - 1
End With
End Sub
Private Sub HighlightText(sKeyword As String, iColour As Long)
Dim nStart As Integer, sPrevChar As String, sNextChar As String
Dim iPos As Long
nStart = InStr(1, UCase(RichTextBox1.Text), sKeyword, vbTextCompare)
Do While nStart <> 0
If nStart > 1 Then
sPrevChar = Mid$(RichTextBox1.Text, nStart - 1, 1)
Else
sPrevChar = " "
End If
If Len(RichTextBox1.Text) >= nStart + Len(sKeyword) Then
sNextChar = Mid$(RichTextBox1.Text, nStart + Len(sKeyword), 1)
Else
sNextChar = " "
End If
If (sPrevChar = Chr(32) Or sPrevChar = Chr(13) Or _
sPrevChar = Chr(10) Or sPrevChar = Chr(9)) And _
(sNextChar = Chr(32) Or sNextChar = Chr(13) Or _
sNextChar = Chr(10) Or sNextChar = Chr(9) Or sNextChar = ".") Then
With RichTextBox1
iPos = .SelStart
.SelStart = nStart - 1
.SelLength = Len(sKeyword)
.SelColor = iColour
.SelText = sKeyword
.SelStart = Len(RichTextBox1.Text)
.SelColor = iColour
.SelStart = iPos
End With
End If
nStart = InStr(nStart + Len(sKeyword), UCase(RichTextBox1.Text), sKeyword, vbTextCompare)
Loop
End Sub
Private Sub RichTextBox1_Change()
With RichTextBox1
.SelStart = 0
.SelColor = vbBlack
.SelStart = Len(.Text)
End With
' Add more custom words here
UnHighlightText vbBlack
HighlightText "END", vbRed
HighlightText "GOTO", vbYellow
HighlightText "IF", vbBlue
End Sub
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|