title: Receive and control serial device data in visual basic
body: <p>I have a serial device which sends me data at the baudrate of 38400 and i get it like this <code>?@D00014C000 000</code>. I can see data comes in on a ritchtextbox but what im trying to do is to use some characters from the string in a list box. 
  For example i want characters "14C" appears in the listbox3. I tried the substring and mid function but listbox lidnt work properly and losses characters or confuse them . Here is my code. Any suggestions please??</p>
  
  <pre><code> Imports System
   Imports System.ComponentModel
   Imports System.Threading
   Imports System.IO.Ports
  
   Public Class frmMain
   Dim myPort As Array
   Delegate Sub SetTextCallback(ByVal [text] As String)
  
  
  
  Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
      ReceivedText(SerialPort1.ReadExisting())
  
  End Sub
  
  Private Sub ReceivedText(ByVal [text] As String)
      If Me.rtbReceived.InvokeRequired Then
          Dim x As New SetTextCallback(AddressOf ReceivedText)
          Me.Invoke(x, New Object() {(text)})
  
      Else
          Me.rtbReceived.Text &amp;= [text]
            Dim fine As String = Mid([text], 7, 3)
          Dim list As Integer = ListBox3.Items.Add(fine)
      End If
  
  End Sub
  </code></pre>
  
  <p>End Class</p>
  
  <p>Here is<a href="https://i.stack.imgur.com/kM9mV.png" rel="nofollow noreferrer">PICTURE 1</a> what happens 
  <a href="https://i.stack.imgur.com/pUCwd.png" rel="nofollow noreferrer">Picture2</a></p>