'From Megatron
Private Sub HighlightText(sKeyword As String, iColour As Long)
Dim nStart As Integer, sPrevChar As String, sNextChar As String
nStart = InStr(1, LCase(frmMain.rtbFormat.Text), sKeyword)
Do While nStart <> 0
If nStart > 1 Then
sPrevChar = Mid$(frmMain.rtbFormat.Text, nStart - 1, 1)
Else
sPrevChar = " "
End If
DoEvents
If Len(frmMain.rtbFormat.Text) >= nStart + Len(sKeyword) Then
sNextChar = Mid$(frmMain.rtbFormat.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) Or sPrevChart = Chr(46)) And _
(sNextChar = Chr(32) Or sNextChar = Chr(13) Or _
sNextChar = Chr(10) Or sNextChar = Chr(9) Or sNextChar = Chr(40)) Then
With frmMain.rtbFormat
.SelStart = nStart - 1
.SelLength = Len(sKeyword)
.SelColor = iColour
.SelText = StrConv(sKeyword, vbProperCase)
.SelStart = Len(frmMain.rtbFormat.Text)
.SelColor = iColour
End With
End If
nStart = InStr(nStart + Len(sKeyword), LCase(frmMain.rtbFormat.Text), sKeyword)
Loop
End Sub
Public Sub FormatCode(ByRef tmpRTB As RichTextBox)
Dim oldselstart As Long
Dim oldsellen As Long
frmMain.rtbFormat.TextRTF = tmpRTB.TextRTF
oldselstart = tmpRTB.SelStart
oldsellen = tmpRTB.SelLength
With frmMain.rtbFormat
.SelStart = 0
.SelLength = Len(.Text)
.SelColor = lngTextColor
.SelStart = Len(.Text)
End With
' Add more custom words here
HighlightText "if", lngKeywordColor
HighlightText "doevents", lngKeywordColor
HighlightText "then", lngKeywordColor
HighlightText "else", lngKeywordColor
HighlightText "end", lngKeywordColor
HighlightText "with", lngKeywordColor
HighlightText "select", lngKeywordColor
HighlightText "case", lngKeywordColor
HighlightText "private", lngKeywordColor
HighlightText "public", lngKeywordColor
HighlightText "dim", lngKeywordColor
HighlightText "sub", lngKeywordColor
HighlightText "function", lngKeywordColor
HighlightText "do", lngKeywordColor
HighlightText "loop", lngKeywordColor
HighlightText "for", lngKeywordColor
HighlightText "next", lngKeywordColor
HighlightText "each", lngKeywordColor
HighlightText "integer", lngKeywordColor
HighlightText "boolean", lngKeywordColor
HighlightText "long", lngKeywordColor
HighlightText "double", lngKeywordColor
HighlightText "variant", lngKeywordColor
HighlightText "string", lngKeywordColor
HighlightText "single", lngKeywordColor
HighlightText "byte", lngKeywordColor
HighlightText "date", lngKeywordColor
HighlightText "format", lngKeywordColor
HighlightText "cdate", lngKeywordColor
HighlightText "cvar", lngKeywordColor
HighlightText "cbyte", lngKeywordColor
HighlightText "cbool", lngKeywordColor
HighlightText "cint", lngKeywordColor
HighlightText "clng", lngKeywordColor
HighlightText "csng", lngKeywordColor
HighlightText "cdbl", lngKeywordColor
HighlightText "const", lngKeywordColor
HighlightText "option base 1", lngKeywordColor
HighlightText "option base 0", lngKeywordColor
HighlightText "until", lngKeywordColor
HighlightText "while", lngKeywordColor
HighlightText "option explicit", lngKeywordColor
HighlightText "byval", lngKeywordColor
HighlightText "byref", lngKeywordColor
HighlightText "declare", lngKeywordColor
HighlightText "global", lngKeywordColor
HighlightText "true", lngKeywordColor
HighlightText "false", lngKeywordColor
HighlightText "mod", lngKeywordColor
HighlightText "as", lngKeywordColor
HighlightText "lib", lngKeywordColor
HighlightText "open", lngKeywordColor
HighlightText "close", lngKeywordColor
HighlightText "append", lngKeywordColor
HighlightText "output", lngKeywordColor
HighlightText "input", lngKeywordColor
HighlightText "print", lngKeywordColor
HighlightText "write", lngKeywordColor
HighlightText "binary", lngKeywordColor
HighlightText "access", lngKeywordColor
HighlightText "xor", lngKeywordColor
HighlightText "or", lngKeywordColor
HighlightText "and", lngKeywordColor
HighlightText "in", lngKeywordColor
HighlightText "like", lngKeywordColor
HighlightText "typeof", lngKeywordColor
HighlightText "object", lngKeywordColor
HighlightText "ubound", lngKeywordColor
HighlightText "lbound", lngKeywordColor
HighlightText "to", lngKeywordColor
HighlightText "on", lngKeywordColor
HighlightText "error", lngKeywordColor
HighlightText "goto", lngKeywordColor
Call FindComments(lngCommentColor)
tmpRTB.TextRTF = frmMain.rtbFormat.TextRTF
tmpRTB.SelStart = oldselstart
tmpRTB.SelLength = oldsellen
tmpRTB.SelColor = lngTextColor
End Sub