Results 1 to 8 of 8

Thread: Richtextbox Change color of define word URGENT PLEASE

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    98

    Resolved Richtextbox Change color of define word URGENT PLEASE

    Hi, i find on this forum info about changing the colors of a word in a richtextbox but id like to know if we can change more than one word's color.
    cause presently when i change the color of one word it works but if id like to change another word in the same rtb, the color change but the other one become black like the other one..

    Private Sub HighlightText(sKeyword As String, iColour As Long)
    Dim nStart As Integer, sPrevChar As String, sNextChar As String

    With rtbCaracteristique
    .SelStart = 0
    .SelLength = Len(.Text)
    .SelColor = vbBlack
    .SelStart = Len(.Text)
    End With

    nStart = InStr(1, LCase(rtbCaracteristique.Text), sKeyword, vbTextCompare)

    Do While nStart <> 0
    If nStart > 1 Then
    sPrevChar = Mid$(rtbCaracteristique.Text, nStart - 1, 1)
    Else
    sPrevChar = " "
    End If

    If Len(rtbCaracteristique.Text) >= nStart + Len(sKeyword) Then
    sNextChar = Mid$(rtbCaracteristique.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) Or sNextChar = ".") Then
    With rtbCaracteristique
    .SelStart = nStart - 1
    .SelLength = Len(sKeyword)
    .SelColor = iColour
    .SelText = StrConv(sKeyword, vbProperCase)
    .SelStart = Len(rtbCaracteristique.Text)
    .SelColor = iColour
    End With
    End If

    nStart = InStr(nStart + Len(sKeyword), LCase(rtbCaracteristique.Text), sKeyword, vbTextCompare)
    Loop
    End Sub


    so if any ideas,,,,let me know
    thanks
    Last edited by DesyM; May 12th, 2005 at 10:11 AM. Reason: urgent please

  2. #2

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    98

    Re: Richtextbox Change color of define word URGENT PLEASE

    anybody has an idea please ?

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

    Re: Richtextbox Change color of define word URGENT PLEASE


  4. #4

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    98

    Cool Re: Richtextbox Change color of define word URGENT PLEASE

    that's not really what i want because,
    id like to choose some important words like private,int, etc and define that when this word appear in the rtb, that this word change color for the color ive already define

    but the link you give me is a good start

    thanks

    any other idea ?

  5. #5
    Hyperactive Member Arachnid13's Avatar
    Join Date
    Jan 2003
    Location
    England
    Posts
    327

    Re: Richtextbox Change color of define word URGENT PLEASE

    try this, i made it a while ago and it checks through a rich text box and compares each word with a list of keywords(also supplied) and turns them blue. it also checks for anything after a ' and turns it green and ignores writing in " quotations to imitate the vb editor. copy some code into it and take a look, it sounds like this is the kind of thing you want to do.

    Vb code formatter
    Do you wake up in the morning feeling sleepy and grumpy? Then you must be Snow White

  6. #6
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Richtextbox Change color of define word URGENT PLEASE

    Have you seen This Post Yet?
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  7. #7

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    98

    Thumbs up Re: Richtextbox Change color of define word URGENT PLEASE

    thanks guys , ill look at this this morning and give you some feedback

  8. #8

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    98

    Resolved Re: Richtextbox Change color of define word URGENT PLEASE

    Ok thanks you it works, i found something on msdn and it help me to conclude that problem

    i use that code

    Private Sub tvw_NodeClick(ByVal Node As MSComctlLib.Node)
    Dim i As Integer
    i = 0
    Dim retour As Integer
    Dim word(3) As String
    word(0) = "range"
    word(1) = "sensor"
    word(2) = "in"

    While i < 3
    ' Statement block to be executed for each value of counter.
    retour = FindMyText(word(i))
    'select case
    If (retour >= 0) Then
    rtbCaracteristique.SelText = word(i)
    rtbCaracteristique.SelStart = retour
    rtbCaracteristique.SelLength = Len(word(i))
    Select Case word(i)
    Case "range": rtbCaracteristique.SelColor = vbRed
    Case "sensor": rtbCaracteristique.SelColor = vbGreen
    Case "in": rtbCaracteristique.SelColor = vbBlue
    End Select
    MsgBox "trouve"
    Else
    MsgBox "pas trouve"
    End If

    i = i + 1
    rtbCaracteristique.SelStart = 0
    Wend
    End Sub

    with the help of the method find on the msdn
    thanks

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