.NET (Core and Framework)
Convert.ToInt32 expects a string containing a single numeric value, and returns a single
You are trying to convert a string containing multiple numeric values, and expecting an array of
You would need to split the string, and convert each part separately.
Convert.ToInt32(ByVal value As String)[^] does not allow you to use a Hex prefix. Neither the VB prefix (
&H) nor the C# prefix (
0x) will work.
Instead, you need to remove the prefix and call the overload which accepts the base you want to convert from:
Convert.ToInt32(ByVal value As String, ByVal fromBase As Integer)[^]
(NB: The C# prefix would work with this overload, but the VB.NET prefix won't.)
Dim parts() As String = strReturn.Split(" "c)
Dim buffer() As Integer = Array.ConvertAll(parts, Function(p) Convert.ToInt32(p.Substring(2), 16))
You're converting the values to
Integer, but Write[^] expects an array of
It would be much simpler to use the Encoding[^] class to convert the string to a series of bytes:
Dim Number1 As String = "2812"
Dim Str As String = "ATDT" & Number1 & "R" & Chr(&HD)
Dim buffer() As Byte = System.Text.Encoding.ASCII.GetBytes(Str)
frmMain.SerialPort1.Write(buffer, 0, buffer.Length)
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
modified 19-Sep-17 7:38am.
General News Suggestion Question Bug Answer Joke Praise Rant Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.