Quote Originally Posted by Tempestknight
Sure
VB Code:
  1. Option Explicit
  2.  
  3. Private Sub HighlightText(sKeyword As String, iColour As Long)
  4.     Dim nStart As Integer, sPrevChar As String, sNextChar As String
  5.                                                
  6.     nStart = InStr(1, UCase(RichTextBox1.Text), sKeyword, vbTextCompare)
  7.                                                                                  
  8.     Do While nStart <> 0
  9.         If nStart > 1 Then
  10.             sPrevChar = Mid$(RichTextBox1.Text, nStart - 1, 1)
  11.         Else
  12.             sPrevChar = " "
  13.         End If
  14.                                                        
  15.         If Len(RichTextBox1.Text) >= nStart + Len(sKeyword) Then
  16.             sNextChar = Mid$(RichTextBox1.Text, nStart + Len(sKeyword), 1)
  17.         Else
  18.             sNextChar = " "
  19.         End If
  20.                                                            
  21.         If (sPrevChar = Chr(32) Or sPrevChar = Chr(13) Or _
  22.         sPrevChar = Chr(10) Or sPrevChar = Chr(9)) And _
  23.         (sNextChar = Chr(32) Or sNextChar = Chr(13) Or _
  24.         sNextChar = Chr(10) Or sNextChar = Chr(9) Or sNextChar = ".") Then
  25.             With RichTextBox1
  26.                 .SelStart = nStart - 1
  27.                 .SelLength = Len(sKeyword)
  28.                 .SelColor = iColour
  29.                 .SelText = sKeyword
  30.                 .SelStart = Len(RichTextBox1.Text)
  31.                 .SelColor = iColour
  32.             End With
  33.         End If
  34.                                                  
  35.         nStart = InStr(nStart + Len(sKeyword), UCase(RichTextBox1.Text), sKeyword, vbTextCompare)
  36.     Loop
  37. End Sub
  38.  
  39. Private Sub RichTextBox1_Change()
  40.     With RichTextBox1
  41.        .SelStart = 0
  42.        
  43.        .SelColor = vbBlack
  44.        .SelStart = Len(.Text)
  45.     End With
  46.    
  47.                                        
  48.     ' Add more custom words here
  49.     HighlightText "END", vbRed
  50.     HighlightText "GOTO", vbYellow
  51.     HighlightText "IF", vbBlue
  52. 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:
  1. Option Explicit
  2.  
  3. Private Sub UnHighlightText(iColour As Long)
  4.     Dim iPos As Long
  5.    
  6.     With RichTextBox1
  7.         iPos = .SelStart
  8.         .SelStart = 0
  9.         .SelLength = Len(.Text)
  10.         .SelColor = iColour
  11.         .SelStart = iPos - 1
  12.     End With
  13. End Sub
  14.  
  15. Private Sub HighlightText(sKeyword As String, iColour As Long)
  16.     Dim nStart As Integer, sPrevChar As String, sNextChar As String
  17.     Dim iPos As Long
  18.                                                
  19.     nStart = InStr(1, UCase(RichTextBox1.Text), sKeyword, vbTextCompare)
  20.                                                                                  
  21.     Do While nStart <> 0
  22.         If nStart > 1 Then
  23.             sPrevChar = Mid$(RichTextBox1.Text, nStart - 1, 1)
  24.         Else
  25.             sPrevChar = " "
  26.         End If
  27.                                                        
  28.         If Len(RichTextBox1.Text) >= nStart + Len(sKeyword) Then
  29.             sNextChar = Mid$(RichTextBox1.Text, nStart + Len(sKeyword), 1)
  30.         Else
  31.             sNextChar = " "
  32.         End If
  33.                                                            
  34.         If (sPrevChar = Chr(32) Or sPrevChar = Chr(13) Or _
  35.         sPrevChar = Chr(10) Or sPrevChar = Chr(9)) And _
  36.         (sNextChar = Chr(32) Or sNextChar = Chr(13) Or _
  37.         sNextChar = Chr(10) Or sNextChar = Chr(9) Or sNextChar = ".") Then
  38.             With RichTextBox1
  39.                 iPos = .SelStart
  40.                 .SelStart = nStart - 1
  41.                 .SelLength = Len(sKeyword)
  42.                 .SelColor = iColour
  43.                 .SelText = sKeyword
  44.                 .SelStart = Len(RichTextBox1.Text)
  45.                 .SelColor = iColour
  46.                 .SelStart = iPos
  47.             End With
  48.         End If
  49.                                                  
  50.         nStart = InStr(nStart + Len(sKeyword), UCase(RichTextBox1.Text), sKeyword, vbTextCompare)
  51.     Loop
  52. End Sub
  53.  
  54. Private Sub RichTextBox1_Change()
  55.     With RichTextBox1
  56.        .SelStart = 0
  57.        
  58.        .SelColor = vbBlack
  59.        .SelStart = Len(.Text)
  60.     End With
  61.    
  62.                                        
  63.     ' Add more custom words here
  64.     UnHighlightText vbBlack
  65.     HighlightText "END", vbRed
  66.     HighlightText "GOTO", vbYellow
  67.     HighlightText "IF", vbBlue
  68. End Sub