-
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?
-
use a richtext box instead of an ordinary textbox
-
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
-
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?