Results 1 to 4 of 4

Thread: Change colour of text

  1. #1

    Thread Starter
    Fanatic Member Gary.Lowe's Avatar
    Join Date
    May 2000
    Location
    In my sphere of influence
    Posts
    621

    Unhappy

    Hi All

    I have a procedure that adds a line to a text box once a certain task is completed.

    It is as follows
    Code:
    Private Sub WriteLog(ByVal sInfo As String, Optional AddDate As Integer, Optional iInfoType As Integer)
        If AddDate = 1 Then
            Me.txtProg = Me.txtProg & sInfo & vbCrLf
        Else
            Select Case iInfoType
                Case 0
                    If Me.txtProg = "" Then
                        Me.txtProg = Date & Space(1) & Time & ": " & sInfo & vbCrLf
                    Else
                        Me.txtProg = Me.txtProg & Date & Space(1) & Time & ": " & sInfo & vbCrLf
                    End If
                Case 1
                    If Me.txtProg = "" Then
                        Me.txtProg = Date & Space(1) & Time & ": " & sInfo & vbCrLf
                    Else
                        Me.txtProg = Me.txtProg & Date & Space(1) & Time & ": " & sInfo & vbCrLf
                    End If
            End Select
        End If
        Me.txtProg.SelStart = Len(Me.txtProg)
        DoEvents
    End Sub
    If the iInfoType is equal to 1 this is because the the log info is an error

    I want to be able to write the log text with iInfoType 0 to be blue and the log text with iInfoType 1 to be red.

    Can you help?
    Gary Lowe
    VB6 (Enterprise) SP5
    ADO 2.6
    SQL Server 7 SP3

    OK I know my spelling and grammer is crap so don't quote me on it!

    To err is human to take the P! is only natural !!

    Click on the top section of image for Marcus Miller website and bottom section of image for 'Run For Cover' sound clip


  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    use a richtext box instead of an ordinary textbox
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3
    Guest
    That's correct. A standard TextBox cannot support multicolours.

    When using a RichTextBox, use the SelColor property to change the colour.
    Code:
    RichTextbox1.SelColor = vbRed
    'Call your WriteLog function here

  4. #4

    Thread Starter
    Fanatic Member Gary.Lowe's Avatar
    Join Date
    May 2000
    Location
    In my sphere of influence
    Posts
    621
    Thanks Guys

    Megatron, I've tried that but it doesn't seem to change the colour once you have set it.

    I have posted the code to show where it should change the text colour.
    Code:
    Private Sub WriteLog(ByVal sInfo As String, Optional AddDate As Integer, Optional iInfoType As Integer)
        If AddDate = 1 Then
            'Colour should be blue as this is the end of the task.
            txtProg.SelColor = vbBlue
            Me.txtProg = Me.txtProg & sInfo & vbCrLf
        Else
            Select Case iInfoType
                Case 0
                    'The colour should be blue meaning it has completed the task without incidents                
                    txtProg.SelColor = vbBlue
                    If Me.txtProg.Text = "" Then
                        Me.txtProg.Text = Date & Space(1) & Time & ": " & sInfo & vbCrLf
                    Else
                        Me.txtProg.Text = Me.txtProg.Text & Date & Space(1) & Time & ": " & sInfo & vbCrLf
                    End If
                Case 1
                    'The colour should be red here to indicate an error was encountered.
                    txtProg.SelColor = vbRed
                    If Me.txtProg.Text = "" Then
                        Me.txtProg.Text = Date & Space(1) & Time & ": " & sInfo & vbCrLf
                    Else
                        Me.txtProg.Text = Me.txtProg.Text & Date & Space(1) & Time & ": " & sInfo & vbCrLf
                    End If
            End Select
        End If
        Me.txtProg.SelStart = Len(Me.txtProg.Text)
        DoEvents
    End Sub
    How do I get it to change the colour of the text?
    Gary Lowe
    VB6 (Enterprise) SP5
    ADO 2.6
    SQL Server 7 SP3

    OK I know my spelling and grammer is crap so don't quote me on it!

    To err is human to take the P! is only natural !!

    Click on the top section of image for Marcus Miller website and bottom section of image for 'Run For Cover' sound clip


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