Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

RTB Replace Text Colors Not working

Posted on 2004-08-12
4
Medium Priority
?
328 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 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
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…
Suggested Courses

715 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