Not a Member Yet,
Click here to Register

ID: 254
Viewed: 2723
Added: Jul 26, 2002
Version:
Snippet uploaded by: snippet
Written By: unknown
Demo: Sorry, no demo



User Rated at: 0 Stars
Rate This:

Thank you for your vote. Please wait...

It appears you already voted for this snippet

It appears your vote value was empty

Add to a Form with a RichTextBox.

Highlight all by clicking in box
<!---Declaration--->
Option Explicit
Const vbDarkBlue = &H800000
Const vbDarkGreen = &H8000&

Highlight All
<!---Code--->
'code:

Private Sub HighlightText(sKeyword As String, iColour As Long)

Dim nStart As Integer, sPrevChar As String, sNextChar As String

nStart = InStr(1, LCase(RichTextBox1.Text), sKeyword)

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)) Then
With RichTextBox1
.SelStart = nStart - 1
.SelLength = Len(sKeyword)
.SelColor = vbDarkBlue
.SelText = StrConv(.SelText, vbProperCase)
.SelStart = Len(RichTextBox1.Text)
.SelColor = iColour
End With

End If

nStart = InStr(nStart + Len(sKeyword), LCase(RichTextBox1.Text), sKeyword)
Loop

End Sub

Private Sub RichTextBox1_Change()
With RichTextBox1
.SelStart = 0
.SelLength = Len(.Text)
.SelColor = vbBlack
.SelStart = Len(.Text)
End With

' Add more custom words here
HighlightText "if", vbBlue
HighlightText "then", vbBlue
HighlightText "end", vbBlue
HighlightText "else", vbBlue
HighlightText "open", vbBlue
HighlightText "sub", vbBlue
HighlightText "exit", vbBlue
HighlightText "with", vbBlue
HighlightText "close", vbBlue
HighlightText "dim", vbBlue
HighlightText "as", vbBlue
HighlightText "private", vbBlue
HighlightText "get", vbBlue
HighlightText "call", vbBlue
HighlightText "option explicit", vbBlue
HighlightText "for", vbBlue
HighlightText "next", vbBlue
End Sub
;


No Comments to show

Please completely fill out the form below if you want to review this snippet. All reviews are subject to validation.


Replying to a Comment...


Adding your comment. Please wait...

Thanks for adding your comment!. After further review it will be added.

There was a problem adding your comment. Please try again.

Please complete all the fields in the form before sending.

© 2002 - 2024 snippetlibrary.com All Rights Reserved. Conditions
Do NOT follow this link or you will be banned from the site!