Results 1 to 6 of 6

Thread: Color Changing,,,,,,,

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 1999
    Location
    Camas, WA, USA
    Posts
    3

    Post

    can some one please tell me how to make the text color change if the text is a certain thing??? (like on html editors.....when you type <./h1> the color is green)

  2. #2
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544

    Post

    You can use the BackColor and ForeColor statements.

    To the change the ForeColor on a label, type the folowing code: (Place a label on a form)

    Private Sub Form_Load()
    Label1.ForeColor = &HFF&
    End Sub

    Use the same methods with the BackColor(use another color : O ))

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 1999
    Location
    Camas, WA, USA
    Posts
    3

    Post

    thank you for the reply but i already know how to do that but i need to know how to change the color if the TEXT is a certain string......for example:

    Private Sub Text1_Change()
    htmlstring = text1
    if htmlstring = "<h1>" then
    text1.forecolor = "&h0"
    End if
    End Sub

    do ya get what i mean now????

  4. #4
    Member
    Join Date
    Jan 2000
    Location
    Glasgow, MT, USA
    Posts
    44

    Post

    look for something called HTML TAG, it will change the < , > , and everything in between

  5. #5
    Hyperactive Member Juan Carlos Rey's Avatar
    Join Date
    Aug 1999
    Location
    Mendoza, Argentina
    Posts
    301

    Post

    This same question has been asked many times not long before in this Forum. Do a search with html, color, tags, RichTextBox, etc. and you'll find something I'm sure...

  6. #6
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Here's some Code I posted a while back on the same question, although you can't use a Standard Textbox, (It doesn't support multicolored text), so you'll have to use a RichTextBox:
    Code:
    Private sLookUp(9, 1) As String
    
    Private Sub Form_Load()
        'Create Lookup Table
        sLookUp(0, 0) = "vb-world"
        sLookUp(0, 1) = Trim(Str(vbBlue))
        sLookUp(1, 0) = "is"
        sLookUp(1, 1) = Trim(Str(vbRed))
        sLookUp(2, 0) = "the"
        sLookUp(2, 1) = Trim(Str(vbGreen))
        sLookUp(3, 0) = "best"
        sLookUp(3, 1) = Trim(Str(vbCyan))
        'Add More Here
    End Sub
    
    Private Sub RichTextBox1_KeyUp(KeyCode As Integer, Shift As Integer)
        'Find the Word Currently under the Text Caret
        Dim iStart As Long
        Dim iEnd As Long
        Dim iMatch As Integer
        Dim sKeyWord As String
        Dim iPos As Long
        
        With RichTextBox1
            iPos = .SelStart
            If iPos Then
                If Mid(.Text, iPos, 1) <> " " Then
                    iStart = InStrRev(.Text, " ", .SelStart) + 1
                    iEnd = InStr(iStart, .Text, " ")
                    If iEnd = 0 Then iEnd = Len(.Text)
                    'Check for a Match
                    sKeyWord = Trim(Mid$(.Text, iStart, iEnd - iStart + 1))
                    Caption = sKeyWord & " : " & Len(sKeyWord)
                    iMatch = MatchKeyWord(sKeyWord)
                    .SelStart = iStart - 1
                    .SelLength = Len(sKeyWord)
                    If iMatch Then
                        .SelColor = Val(sLookUp(iMatch - 1, 1))
                    Else
                        .SelColor = vbBlack
                    End If
                    .SelStart = iPos
                End If
            End If
            .SelColor = vbBlack
        End With
    End Sub
    
    Private Function MatchKeyWord(ByVal sWord As String) As Integer
        'Check Word for a Match in the Lookup Table
        Dim iLookUp As Integer
        For iLookUp = 0 To UBound(sLookUp)
            If LCase(sWord) = LCase(sLookUp(iLookUp, 0)) Then Exit For
        Next
        If iLookUp <= UBound(sLookUp) Then MatchKeyWord = iLookUp + 1
    End Function
    
    Private Function InStrRev2(ByVal sString As String, ByVal sChars As String, Optional ByVal lPos As Long = 1) As Long
        'Duplicate of the VB6 Function InstrRev
        'If you Don't have VB6, Rename InStrRev in the
        'KeyUp Event to InstrRev2 to use this Routine instead.
        If Len(sString) = 0 Then Exit Function
        If lPos = 1 Then lPos = Len(sString)
        While Mid(sString, lPos, 1) <> sChars And lPos > 1
            lPos = lPos - 1
        Wend
        If lPos = 1 And Left(sString, 1) <> sChars Then
            InStrRev2 = 0
        Else
            InStrRev2 = lPos
        End If
    End Function
    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]
    Certified AllExperts Expert

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