Hi,
I would like to display my text in four different colors based on a condition. I have implemented a peice of code for this operation but it is not working instead i got a exception message which i don't understand.
I got this exception from a function where i had written for colored text and i run my code without this color selection which is working fine. However, i have not got any colored text instead i got an exception. Can some help me where i am doing mistake.
Thank you.
The function is here..
Private Sub OnDataReceive(ByVal DataString As String)
Dim Buff As String
Dim DataStr As String = ""
Try
theDate = DateTime.Now
Buff = DataString
For i = 1 To Buff.Length
DataStr &= ("<" & Hex(Asc(Mid("" & Buff, i, 1))) & ">")
Next
If Convert.ToByte(Asc(Mid(DataStr, 11, 12))) = 0 Then
RichTextBox1.SelectionColor = Color.Blue
ElseIf Convert.ToByte(Asc(Mid(DataStr, 11, 12))) = 1 Then
RichTextBox1.SelectionColor = Color.Red
ElseIf Convert.ToByte(Asc(Mid(DataStr, 11, 12))) = 2 Then
RichTextBox1.SelectionColor = Color.Black
ElseIf Convert.ToByte(Asc(Mid(DataStr, 11, 12))) = 3 Then
RichTextBox1.SelectionColor = Color.Pink
End If
RichTextBox1.AppendText(theDate & ":- " & DataStr & Environment.NewLine)
Catch ex As Exception
MsgBox(ex.Message & "From OnDataReceive function")
End Try
End Sub
I would like to display my text in four different colors based on a condition. I have implemented a peice of code for this operation but it is not working instead i got a exception message which i don't understand.
I got this exception from a function where i had written for colored text and i run my code without this color selection which is working fine. However, i have not got any colored text instead i got an exception. Can some help me where i am doing mistake.
Thank you.
The function is here..
Private Sub OnDataReceive(ByVal DataString As String)
Dim Buff As String
Dim DataStr As String = ""
Try
theDate = DateTime.Now
Buff = DataString
For i = 1 To Buff.Length
DataStr &= ("<" & Hex(Asc(Mid("" & Buff, i, 1))) & ">")
Next
If Convert.ToByte(Asc(Mid(DataStr, 11, 12))) = 0 Then
RichTextBox1.SelectionColor = Color.Blue
ElseIf Convert.ToByte(Asc(Mid(DataStr, 11, 12))) = 1 Then
RichTextBox1.SelectionColor = Color.Red
ElseIf Convert.ToByte(Asc(Mid(DataStr, 11, 12))) = 2 Then
RichTextBox1.SelectionColor = Color.Black
ElseIf Convert.ToByte(Asc(Mid(DataStr, 11, 12))) = 3 Then
RichTextBox1.SelectionColor = Color.Pink
End If
RichTextBox1.AppendText(theDate & ":- " & DataStr & Environment.NewLine)
Catch ex As Exception
MsgBox(ex.Message & "From OnDataReceive function")
End Try
End Sub