Link to home
Start Free TrialLog in
Avatar of andyakira
andyakira

asked on

RTB Replace Text Colors Not working

basically Im trying to replace the text in the RTB when it detects the symbol "Á" + Letter (each letter represents a different color), It's suppose to be replace text colors when text is added with Á symbol, but it dosnt seem to be working. any suggestions?


If InStr(Form1.RTB.text, "Á") > 0 Then

Dim sOne As String, iOne As Long
With Form1.RTB

Do Until InStr(.text, "Á") = 0
  iOne = InStr(.text, "Á"): .SelStart = iOne: .SelLength = 1: sOne = .SelText: .SelStart = iOne - 1: .SelLength = Len(.text)
 
  Select Case sOne
    Case "R": .SelColor = vbGreen
    Case "P": .SelColor = vbWhite
    Case "S": .SelColor = vbYellow
    Case "T": .SelColor = vbCyan
    Case "Q": .SelColor = &H808080
    Case "V": .SelColor = vbCyan
    Case "U": .SelColor = vbCyan
    Case "Y": .SelColor = vbRed
  End Select
  .SelStart = iOne - 1: .SelLength = 2: .SelText = ""
Loop

End if
Avatar of JR2003
JR2003

I take it you want to just change the colour of the letter next to the Á symbol and delete the Á symbol?

This code does the job:

Private Sub Command1_Click()
   
    Dim iPosStart As Long
    Dim sText As String
    iPosStart = 1 'Initialise
   
    With RTB
   
        Do Until InStr(iPosStart, .Text, "Á") = 0
            iPosStart = InStr(.Text, "Á")
            .SelStart = iPosStart - 1
            .SelLength = 1
            .SelText = ""
            .SelLength = 1
           
            Debug.Print .SelText
           
            Select Case .SelText
                Case "R": .SelColor = vbGreen
                Case "P": .SelColor = vbWhite
                Case "S": .SelColor = vbYellow
                Case "T": .SelColor = vbCyan
                Case "Q": .SelColor = &H808080
                Case "V": .SelColor = vbCyan
                Case "U": .SelColor = vbCyan
                Case "Y": .SelColor = vbRed
                Case Else: .SelColor = RGB(100, 100, 10)
            End Select
        Loop

    End With

End Sub

ASKER CERTIFIED SOLUTION
Avatar of JR2003
JR2003

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of andyakira

ASKER

Hm ÁZ is printing black :(
im trying to get every text after ÁX  to be colored