Hi,
I have an external device transmitting a repeating comma deliminated hex string through the RS-232 port of my computer.
The specific data frame looks like this:
"03 FF 2C 03 FF 2C" ["2C" is the delimiting comma so "3ff,3ff,"]
Essentially, What I'm trying to do is display 1023 in a respective textbox control. since 3FF = 1023 (hex to decimal conversion)
If place a textbox control on my application with the following code:
TextBox1.Text = CType("&H3ff", Integer) I can indeed see that 3ff = 1023
If I place a textbox control on my application with the following code:
I receive the following error:
Conversion from string "&h ?" to type 'Integer' is not valid.
If I run the code without a cast conversion I see jibberish (which makes sense) in the text controls:
specifially "?" in both text fields.
What am I doing wrong?
Thanks for any help!
Ken Ryder
I have an external device transmitting a repeating comma deliminated hex string through the RS-232 port of my computer.
The specific data frame looks like this:
"03 FF 2C 03 FF 2C" ["2C" is the delimiting comma so "3ff,3ff,"]
Essentially, What I'm trying to do is display 1023 in a respective textbox control. since 3FF = 1023 (hex to decimal conversion)
If place a textbox control on my application with the following code:
TextBox1.Text = CType("&H3ff", Integer) I can indeed see that 3ff = 1023
If I place a textbox control on my application with the following code:
VB.NET:
Private Sub SerialPort1_DataReceived(ByVal sender As Object, _
ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
Dim values As String
Dim vArray As Array
Dim sHEX As String
Dim iHex As Integer
values = SerialPort1.ReadExisting
vArray = Split(values, ",")
sHEX = ("&h" + vArray(0))
iHex = CType(sHEX, Integer)
TextBox1.Text = iHex
End Sub
Conversion from string "&h ?" to type 'Integer' is not valid.
If I run the code without a cast conversion I see jibberish (which makes sense) in the text controls:
specifially "?" in both text fields.
VB.NET:
Private Sub SerialPort1_DataReceived(ByVal sender As Object, _
ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
Dim values As String
Dim vArray As Array
values = SerialPort1.ReadExisting
vArray = Split(values, ",")
TextBox1.Text = vArray(0)
TextBox2.Text = vArray(1)
End Sub
Thanks for any help!
Ken Ryder
Last edited by a moderator: