Results 1 to 40 of 40

Thread: Color coding

Hybrid View

  1. #1
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808

    Re: Color coding

    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
    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.

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    238

    Re: Color coding

    if u test that u will see it ****s up
    The Tempest Shall Never Die.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    238

    Re: Color coding

    ok that still doesn't do what i want it to... it just keeps going same color like last time
    The Tempest Shall Never Die.

  4. #4
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808

    Re: Color coding

    Quote Originally Posted by Tempestknight
    ok that still doesn't do what i want it to... it just keeps going same color like last time
    I don't understand what you need then. Can you posted the sample text you want COLORED, please??
    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.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    238

    Re: Color coding

    ok lol... say if i have

    IF T23, @hast23

    ok i want that whole line blue but then if i i have

    IF T23, @hast23
    1: hey

    i want IF T23, @hast23 to be blue and the 1: hey to be black
    The Tempest Shall Never Die.

  6. #6
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808

    Re: Color coding

    So you want this:

    IF T23, @hast23
    1: hey

    I think I deserve a couple of votes for all this help

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

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    238

    Re: Color coding

    OK lol that all works thank you. but now when u go and say u have

    END

    and u wanna change it to

    END SCENE

    u have it and u try to edit it but it brings you to next line. like u have

    END
    and add scene to it youll end up with

    END S
    CENE
    because it brings you to next line know why? lol and yes i will vote for you :P lol i already gave u one yesterday
    The Tempest Shall Never Die.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width