title: How can I get packets of data from a HEX string in VB.NET?
body: <p>I'm getting a hexadecimal string from a PLC. The data comes from 3 sensors and the string is 12 characters long. For example 00150C950137 so the data for the sensors is 0015, 0C95 and 0137.</p>
  
  <p>I converted the first 4 easily but it gives me an error when I try to convert the 2nd and 3rd. This is what I'm using:</p>
  
  <pre><code>ResData.Text = strRes &amp; ": " &amp; strRes.Substring(0, 4) &amp; " - " &amp; strRes.Substring(4, 4) &amp; " - " &amp; strRes.Substring(8, 4)
  
  Dim lbl1 = strRes.Substring(0, 4).ToString
  lbl1 = Convert.ToByte(lbl1, 16)
  
  Dim lbl2 = strRes.Substring(4, 4).ToString
  lbl2 = Convert.ToByte(lbl2, 16)
  
  Dim prg1 = strRes.Substring(8, 4).ToString
  prg1 = Convert.ToByte(prg1, 16)
  
  Label1.Text = "Plug Catcher: " &amp; lbl1 &amp; " psi"
  Label3.Text = "Manifold: " &amp; lbl2 &amp; " psi"
  MyVerticalProgessBar1.Value = prg1
  </code></pre>
  
  <p>The first line is there to show the whole string and also the 3 different groups of data and it works fine in HEX.</p>
  
  <p>The lbl1 convertion also works. For example 0015 gives me 21. The problem comes with the lbl2 and the prg1. It says:</p>
  
  <blockquote>
    <p>An unhandled exception of type 'System.OverflowException' occurred in
    mscorlib.dll</p>
    
    <p>Additional information: Value was either too large or too small for an
    unsigned byte.</p>
  </blockquote>
  
  <p>Any ideas? Thanks in advance!</p>