Re: convert ASCII to char
All arrays in .NET are zero-based, so your loop should go from 0 to hexnum.Length-1.
Re: convert ASCII to char
Quote:
Originally Posted by Atheist
All arrays in .NET are zero-based, so your loop should go from 0 to hexnum.Length-1.
right...
but for the Mid() function ...the arguement must be greater than 0
how should i do it now?
Re: convert ASCII to char
The Mid function is just kept for legacy support in VB.NET, use the strings Substring method instead.
Re: convert ASCII to char
ok ..after I looked at it in detail....i found the string my device send to me application has some invalid char hiding...
so i use string.trim()
DONE!
Thank you Atheist anyway~
Code:
Dim hexnum As String
Dim converttohex As String
Dim hextonum As Integer
Dim chara As Char
hexnum = txtReceivedMessage.Text.trim() <<<!!!
For i = 0 To Len(hexnum)-1 Step 2
converttohex = hexnum.Substring(i, 2)
hextonum = Convert.ToInt32(converttohex, 16)
chara = Chr(hextonum)
TextBox1.Text += chara
Next i