Solved

RTB Replace Text Colors Not working

Posted on 2004-08-12
4
313 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

726 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