Results 1 to 40 of 40

Thread: Color coding

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    238

    Color coding

    Hrm... lol i wanna make it so that all the END's in a textbox turn red? any ideas how i could do that?
    The Tempest Shall Never Die.

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

    Re: Color coding

    For starters, Textboxes can only have one forecolor. If you want to do that you may need a Rich Text Box.
    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.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    238

    Re: Color coding

    i have a richtextbox i got a color code thing by umm someone on the forum but its not working im tyring to change the word END to red but it don't work
    VB Code:
    1. Private Sub HighlightText(sKeyword As String, iColour As Long)
    2.     Dim nStart As Integer, sPrevChar As String, sNextChar As String
    3.                                                
    4.     nStart = InStr(1, LCase(RichTextBox1.Text), sKeyword)
    5.                                                                                  
    6.     Do While nStart <> 0
    7.         If nStart > 1 Then
    8.             sPrevChar = Mid$(RichTextBox1.Text, nStart - 1, 1)
    9.         Else
    10.             sPrevChar = " "
    11.         End If
    12.                                                        
    13.         If Len(RichTextBox1.Text) >= nStart + Len(sKeyword) Then
    14.             sNextChar = Mid$(RichTextBox1.Text, nStart + Len(sKeyword), 1)
    15.         Else
    16.             sNextChar = " "
    17.         End If
    18.                                                            
    19.         If (sPrevChar = Chr(32) Or sPrevChar = Chr(13) Or _
    20.         sPrevChar = Chr(10) Or sPrevChar = Chr(9)) And _
    21.         (sNextChar = Chr(32) Or sNextChar = Chr(13) Or _
    22.         sNextChar = Chr(10) Or sNextChar = Chr(9)) Then
    23.             With RichTextBox1
    24.                 .SelStart = nStart - 1
    25.                 .SelLength = Len(sKeyword)
    26.                 .SelColor = iColour
    27.                 .SelText = StrConv(sKeyword, vbProperCase)
    28.                 .SelStart = Len(RichTextBox1.Text)
    29.                 .SelColor = iColour
    30.             End With
    31.         End If
    32.                                                  
    33.         nStart = InStr(nStart + Len(sKeyword), LCase(RichTextBox1.Text), sKeyword)
    34.     Loop
    35. End Sub
    36.  
    37. Private Sub Form_Resize()
    38.     RichTextBox1.Move 0, 0, ScaleWidth, ScaleHeight
    39. End Sub
    40.  
    41. Private Sub RichTextBox1_Change()
    42.     With RichTextBox1
    43.        .SelStart = 0
    44.        .SelLength = Len(.Text)
    45.        .SelColor = vbBlack
    46.        .SelStart = Len(.Text)
    47.     End With
    48.    
    49.                                        
    50.     ' Add more custom words here
    51.     HighlightText "END", vbRed
    52. End Sub
    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

    This works...
    Attached Files Attached Files
    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

    kk lol but it goes lower case :\ i need it to stay upper
    The Tempest Shall Never Die.

  6. #6
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Color coding

    Ucase(string)

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    238

    Re: Color coding

    still puts End instead of END :\
    The Tempest Shall Never Die.

  8. #8
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Color coding

    thats impossible. try this then.

    Option Explicit
    Private Sub Form_Load()
    Text1.Text = Replace(Text1.Text, "end", UCase("end"))
    End Sub

  9. #9
    Fanatic Member ZeBula8's Avatar
    Join Date
    Oct 2002
    Posts
    548

    Re: Color coding

    you may want to check this link out for some tips on color coding:

    color coding tips

  10. #10
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Color coding

    How about

    VB Code:
    1. RichTextBox1.SelStart = 1 ' Check First time
    2. do while RichTextBox1.SelStart > 0 ' do until not found anymore
    3.   If RichTextBox1.SelStart <> 1 then
    4. RichTextbox1.SelStart + 3  ' Start at end of the last instance
    5.   endif
    6.   RichTextBox1.Find "END"  ' search for "END"
    7.   if RichTextBox1.SelStart > 0 then  ' if found
    8.     RichTextBox1.SelColor = iColor    ' color it
    9.   endif
    10. loop

    EDIT: Changed to prevent endless loop.
    Last edited by dglienna; Mar 26th, 2005 at 12:38 AM.

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

    Re: Color coding

    The problem is the line that says StrConv(sKeyword, vbProperCase). ProperCase will change the first letter of the word to upper. Change the line
    VB Code:
    1. .SelText = StrConv(sKeyword, vbProperCase)
    to
    VB Code:
    1. .SelText = sKeyword ' StrConv(sKeyword, vbProperCase)
    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.

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

    Re: Color coding

    Based on dglienna's suggesed code (which won't work... sorry, dude)
    VB Code:
    1. Dim lStart As Long
    2.    
    3.     Do
    4.       RichTextBox1.Find sKeyword, lStart ' search for "END"
    5.            
    6.       If RichTextBox1.SelStart < lStart Then
    7.         'We found all the ocurrences!!
    8.         Exit Do
    9.       End If
    10.      
    11.       If RichTextBox1.SelStart > 0 Then  ' if found
    12.         RichTextBox1.SelColor = iColour    ' color it
    13.         RichTextBox1.SelText = sKeyword
    14.       End If
    15.      
    16.       lStart = RichTextBox1.SelStart + Len(sKeyword) + 1
    17.     Loop While RichTextBox1.SelStart > 0 ' do until not found anymore
    However... this way you are not checking the previous and next character. Maybe you want to add this.
    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.

  13. #13
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Color coding

    I use this in my program. Whatever I search for is highlighted.

    VB Code:
    1. .SelStart = 0
    2.     .Find Trim(Line2)
    3.     .SelAlignment = rtfCenter

    and this

    VB Code:
    1. .Find ("[47]")
    2.      .SelBold = 1
    3.      .SelText = Space(4) & "ESTIMATE ONLY"

    so you could certainly use .Find, then .SelColor, then .SelText = "END",
    but I don't think the replacement is even necessary, as shown in the first example. Whatever I .Find is selected. Whatever is selected is then Highlighted.

  14. #14
    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 dglienna
    I use this in my program. Whatever I search for is highlighted.

    VB Code:
    1. .SelStart = 0
    2.     .Find Trim(Line2)
    3.     .SelAlignment = rtfCenter

    and this

    VB Code:
    1. .Find ("[47]")
    2.      .SelBold = 1
    3.      .SelText = Space(4) & "ESTIMATE ONLY"

    so you could certainly use .Find, then .SelColor, then .SelText = "END",
    but I don't think the replacement is even necessary, as shown in the first example. Whatever I .Find is selected. Whatever is selected is then Highlighted.
    The .SelText = "END" part is to change the text to uppercase (in case it was not in upper letters).
    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.

  15. #15
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Color coding

    so why wouldn't the other code work, then? are you saying that it might have been 'end' in the text? then I agree. he didn't state that. as far as searching for "END" and changing the color, that would probably work, as other formatting operations work. I highlight variables that way using BOLD.

  16. #16
    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 dglienna
    so why wouldn't the other code work, then? are you saying that it might have been 'end' in the text? then I agree. he didn't state that. as far as searching for "END" and changing the color, that would probably work, as other formatting operations work. I highlight variables that way using BOLD.
    The code you posted first does not work because it never exit the loop. It keeps looking and finding the first occurence (which is the only word that's highlighted) and never exists the loop. You have to break the code and exit manually or just STOP the execution.
    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.

  17. #17
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Color coding

    Oh. I see now. I added that for multiple instances. You would have to stop resetting the start to .SelStart + 3 until SelStart = 0 (when it wasn't found)

  18. #18
    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 dglienna
    Oh. I see now. I added that for multiple instances. You would have to stop resetting the start to .SelStart + 3 until SelStart = 0 (when it wasn't found)
    The RichTextBox1.SelStart = 0 line was missing.
    VB Code:
    1. Dim lStart As Long
    2.    
    3.     RichTextBox1.SelStart = 0  '<--- Actually... this is the only line that was missing
    4.                                          '(if no ocurrence is found)
    5.     Do
    6. '      RichTextBox1.SelStart = 0 ' Cannot set to 0. Otherwise, always the first word would be found
    7.       RichTextBox1.Find sKeyword, lStart ' search for "END"
    8.            
    9.       If RichTextBox1.SelStart < lStart Then
    10.         'We found all the ocurrences!!
    11.         Exit Do
    12.       End If
    13.      
    14.       If RichTextBox1.SelStart > 0 Then  ' if found
    15.         RichTextBox1.SelColor = iColour    ' color it
    16.         RichTextBox1.SelText = sKeyword
    17.       End If
    18.      
    19.       lStart = RichTextBox1.SelStart + Len(sKeyword) + 1
    20.     Loop While RichTextBox1.SelStart > 0 ' do until not found anymore
    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.

  19. #19

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    238

    Re: Color coding

    OK.... lol so i got it so it stays in upper case but now i wanna make it so that if i have an If statement the whole thing turns blue like in this programming lang an if would look like(Wos scripting)

    If T23, @hastoken23
    (action if u don't got)
    @hastoken23
    (action if u got)

    i wanna make it so that the If turns blue as well as the @hastoken23
    The Tempest Shall Never Die.

  20. #20

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    238

    Re: Color coding

    aha ha :P i got it i just took out the
    .SelStart = 0
    from
    richtextbox1_change()
    thank you all ur the best

    EDIT ok... ill give you an example of what it does now it puts

    If T23, @hast23

    in blue

    but then i put an
    END scene
    and it turns END into red and scene is still in blue :\


    EDIT again lol well now i took out
    .SelLength = Len(.Text)
    as well as
    .SelStart = 0
    and it seems to not do what it did before but now after i type a command
    IF t23, @hast23 (in blue)
    the action that i put will be in blue also :\
    anyone know why?
    Last edited by Tempestknight; Mar 26th, 2005 at 08:31 AM.
    The Tempest Shall Never Die.

  21. #21
    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
    aha ha :P i got it i just took out the
    .SelStart = 0
    from
    richtextbox1_change()
    thank you all ur the best

    EDIT ok... ill give you an example of what it does now it puts

    If T23, @hast23

    in blue

    but then i put an
    END scene
    and it turns END into red and scene is still in blue :\


    EDIT again lol well now i took out
    .SelLength = Len(.Text)
    as well as
    .SelStart = 0
    and it seems to not do what it did before but now after i type a command
    IF t23, @hast23 (in blue)
    the action that i put will be in blue also :\
    anyone know why?
    Can you post your code to test it?
    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.

  22. #22

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    238

    Re: Color coding

    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...
    The Tempest Shall Never Die.

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

  24. #24

    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.

  25. #25

    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.

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

  27. #27

    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.

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

  29. #29

    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.

  30. #30
    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 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
    HTH. I've helped you enough. You have the coloring thing working. All you need now is mess with the code to get it working like you want.... and I don't see you're grateful with the provided 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.     ' Add more custom words here
    65.     UnHighlightText vbBlack
    66.     HighlightText "END", vbRed
    67.     HighlightText "GOTO", vbYellow
    68.     HighlightText "IF", vbBlue
    69. 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.

  31. #31

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    238

    Re: Color coding

    lol i am very grateful lol.Its kinda hard to express feeling on a forum :\ lol u know. I always fiddle around with the code provided before asking questions. As well as search before i ask.... lol but thank you
    The Tempest Shall Never Die.

  32. #32
    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
    lol i am very grateful lol.Its kinda hard to express feeling on a forum :\ lol u know. I always fiddle around with the code provided before asking questions. As well as search before i ask.... lol but thank you
    If you read my signature you'll know what I mean.
    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.

  33. #33

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    238

    Re: Color coding

    Lol ill remember that but i try to give you a point it says
    You must spread some Reputation around before giving it to Mc Brain again.

    so as soon as i get a chance ill give you a point
    The Tempest Shall Never Die.

  34. #34
    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
    Lol ill remember that but i try to give you a point it says
    You must spread some Reputation around before giving it to Mc Brain again.

    so as soon as i get a chance ill give you a point
    Sorry about that.
    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.

  35. #35

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    238

    Re: Color coding

    I feel realy bad asking this sinse u helped me so much but can anyone direct me to a link with all the built in VB colors?
    The Tempest Shall Never Die.

  36. #36
    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
    I feel realy bad asking this sinse u helped me so much but can anyone direct me to a link with all the built in VB colors?
    I don't understand what you need.
    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.

  37. #37

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    238

    Re: Color coding

    lol like vbYellow vbRed vbBlue i dunno them all is there a website(i tired looking) where there is a list of em?
    The Tempest Shall Never Die.

  38. #38
    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
    lol like vbYellow vbRed vbBlue i dunno them all is there a website(i tired looking) where there is a list of em?
    Here's MSDN's text...

    Quote Originally Posted by MSDN
    Color Constants

    Colors
    Constant Value Description
    vbBlack &H0 Black
    vbRed &HFF Red
    vbGreen &HFF00 Green
    vbYellow &HFFFF Yellow
    vbBlue &HFF0000 Blue
    vbMagenta &HFF00FF Magenta
    vbCyan &HFFFF00 Cyan
    vbWhite &HFFFFFF White


    System Colors
    Constant Value Description
    vbScrollBars &H80000000 Scroll bar color
    vbDesktop &H80000001 Desktop color
    vbActiveTitleBar &H80000002 Color of the title bar for the active window
    vbInactiveTitleBar &H80000003 Color of the title bar for the inactive window
    vbMenuBar &H80000004 Menu background color
    vbWindowBackground &H80000005 Window background color
    vbWindowFrame &H80000006 Window frame color
    vbMenuText &H80000007 Color of text on menus
    vbWindowText &H80000008 Color of text in windows
    vbTitleBarText &H80000009 Color of text in caption, size box, and scroll arrow
    vbActiveBorder &H8000000A Border color of active window
    vbInactiveBorder &H8000000B Border color of inactive window
    vbApplicationWorkspace &H8000000C Background color of multiple-document interface (MDI) applications
    vbHighlight &H8000000D Background color of items selected in a control
    vbHighlightText &H8000000E Text color of items selected in a control
    vbButtonFace &H8000000F Color of shading on the face of command buttons
    vbButtonShadow &H80000010 Color of shading on the edge of command buttons
    vbGrayText &H80000011 Grayed (disabled) text
    vbButtonText &H80000012 Text color on push buttons
    vbInactiveCaptionText &H80000013 Color of text in an inactive caption
    vb3DHighlight &H80000014 Highlight color for 3D display elements
    vb3DDKShadow &H80000015 Darkest shadow color for 3D display elements
    vb3DLight &H80000016 Second lightest of the 3D colors after vb3Dhighlight
    vb3DFace &H8000000F Color of text face
    vb3Dshadow &H80000010 Color of text shadow
    vbInfoText &H80000017 Color of text in ToolTips
    vbInfoBackground &H80000018 Background color of ToolTips
    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.

  39. #39

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    238

    Re: Color coding

    Thanks
    The Tempest Shall Never Die.

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

    Re: Color coding

    You might also want to have a look at thr RGB function

    Quote Originally Posted by MSDN
    RGB Function


    Returns aLong whole number representing an RGB color value.

    Syntax

    RGB(red, green, blue)

    The RGB function syntax has thesenamed arguments:

    Part Description
    red Required; Variant (Integer). Number in the range 0–255, inclusive, that represents the red component of the color.
    green Required; Variant (Integer). Number in the range 0–255, inclusive, that represents the green component of the color.
    blue Required; Variant (Integer). Number in the range 0–255, inclusive, that represents the blue component of the color.


    Remarks

    Applicationmethods andproperties that accept a color specification expect that specification to be a number representing an RGB color value. An RGB color value specifies the relative intensity of red, green, and blue to cause a specific color to be displayed.

    The value for anyargument to RGB that exceeds 255 is assumed to be 255.

    The following table lists some standard colors and the red, green, and blue values they include:

    Color Red Value Green Value Blue Value
    Black 0 0 0
    Blue 0 0 255
    Green 0 255 0
    Cyan 0 255 255
    Red 255 0 0
    Magenta 255 0 255
    Yellow 255 255 0
    White 255 255 255
    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
  •  



Click Here to Expand Forum to Full Width