Solved

RTB Replace Text Colors Not working

Posted on 2004-08-12
4
312 Views
Last Modified: 2010-05-02
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
0
Comment
Question by:andyakira
  • 2
  • 2
4 Comments
 
LVL 18

Expert Comment

by:JR2003
ID: 11790898
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

0
 
LVL 18

Accepted Solution

by:
JR2003 earned 125 total points
ID: 11790908
If you want to remove your formatting chars and colou the rest of the text the code defined colour this code will do the job:

Private Sub Command1_Click()

    Dim iPosStart As Long
    Dim sText As String
    Dim iColour As Long
    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": iColour = vbGreen
                Case "P": iColour = vbWhite
                Case "S": iColour = vbYellow
                Case "T": iColour = vbCyan
                Case "Q": iColour = &H808080
                Case "V": iColour = vbCyan
                Case "U": iColour = vbCyan
                Case "Y": iColour = vbRed
                Case Else: iColour = RGB(100, 100, 10)
            End Select
            .SelText = ""
            .SelLength = Len(.Text) - (iPosStart - 1)
            .SelColor = iColour
        Loop

    End With

End Sub

0
 

Author Comment

by:andyakira
ID: 11798809
Hm ÁZ is printing black :(
0
 

Author Comment

by:andyakira
ID: 11798814
im trying to get every text after ÁX  to be colored
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question