title: Reference not set to instance error
body: <p>This is my code, and when I run the project, there are no errors, but when it goes to my Dispense() event "An unhandled exception of type 'System.NullReferenceException' occurred" in the line  ManDis = returnedMessage.Substring(8, 3)</p>
  
  <p>It is necessary to do a try..catch or something?</p>
  
  <p>Thanks!</p>
  
  <pre><code>Module Module1
  
  Public WithEvents ANDI As ANDI_AXC_LIBLib.ANDI_AXC
  Public WithEvents ANDI_LOOP As ANDI_AXC_LIBLib.ANDI_AXC
  
  
  
  Dim MAnufacturer As String
  Public returnedMessage As String
  Dim system As String
  Dim version As String
  Dim software As String
  Dim connecttion As String
  Dim logical As String
  Dim DClass As String
  Dim ID As String
  Dim ServiceCount As String
  Dim servicesupplied As String
  
  
  
  ' ANDI Library access 
  
  Sub Main()
  
      ANDI = New ANDI_AXC
  
  
      'IP list for the console
      Dim addys As New List(Of String)
  
      addys.Add("10.0.99.139")
      addys.Add("10.0.99.138")
      addys.Add("10.0.99.181")
  
  
      For Each addy As String In addys
  
  
  
          With ANDI
              .DeviceClass = "POS01"
              .ServiceClass = "DGS"
              .Mode = ANDI_AXC_LIBLib._COMM_MODE.ETHERNET
              .CommPort = 1
              .EthernetPort = 6627
              .BaudRate = 9600
              .DataBits = 8
              .Parity = ANDI_AXC_LIBLib._PARITY_MODE.NO_PARITY
              .StopBits = 2
  
          End With
          Dim MyResult As ANDI_AXC_LIBLib.CONN_OP_RESULT ' The return value from Open (found in the type library)
  
  
          ANDI.DeviceID = addy
  
  
          ANDI.Close()
          ' Are we already connected?
          If ANDI.Connected Then
              ' Close the connection.
              Call ANDI.Close()
          Else
  
          End If
          ' Open the connection.
          MyResult = ANDI.Open()
          MsgBox(MyResult.ToString())
  
  
  
          If MyResult = ANDI_AXC_LIBLib._CONN_OP_RESULT.CONN_OP_FAILED Then
              Console.WriteLine(ANDI.StatusMessage)
              Console.WriteLine("you are not connected")
  
  
  
          Else
              Console.WriteLine("Press enter to connect to the Allied network")
  
          End If
  
  
  
  
          SendMessage("DIS00 E00", 2)
  
  
  
  
  
          Console.ReadLine()
          Call ANDI.Open()
  
  
  
  
          Console.WriteLine("You are connected to the NexGen at: " &amp; ANDI.DeviceID)
          MsgBox("You are connected!!!!")
          Console.WriteLine("")
  
  
  
  
  
  
          MAnufacturer = returnedMessage.Substring(9, 20)
          Console.WriteLine("Manufacturer = " + MAnufacturer)
  
          'Device Name
          system = returnedMessage.Substring(29, 15)
          Console.WriteLine("Device Name = " + system)
  
          'Version name
          version = returnedMessage.Substring(44, 5)
          Console.WriteLine("Version = " + version)
  
          'Software Identification
          software = returnedMessage.Substring(49, 20)
          Console.WriteLine("Software = " + software)
  
          'Connection Status
          connecttion = returnedMessage.Substring(69, 1)
          Console.WriteLine("Connection Status = " + connecttion)
  
          'Logical Status 
          logical = returnedMessage.Substring(70, 1)
          Console.WriteLine("Logical Status = " + logical)
  
          'Device Class  
          DClass = returnedMessage.Substring(71, 3)
          Console.WriteLine("Device Class = " + DClass)
  
          'ID
          ID = returnedMessage.Substring(74, 2)
          Console.WriteLine("ID = " + ID)
  
          ' number of services supplied 
          ServiceCount = returnedMessage.Substring(76, 2)
          Console.WriteLine("Number of Service = " + ServiceCount)
  
          'services Supplied
          servicesupplied = returnedMessage.Substring(78)
  
  
  
  
          Dim sb As New System.Text.StringBuilder
          For Each s As String In SplitIntoSets(servicesupplied, 3)
              sb.AppendLine(s)
          Next
          Console.WriteLine("Services Suppled ")
          Console.WriteLine("---------------------")
          Console.WriteLine(sb.ToString)
  
      Next
      Console.ReadLine()
  
  End Sub
    Private Sub SendMessage(ByVal message As String, ByVal target As Integer)
  
  
      Dim MyResult As Boolean
      ' Are we connected?
  
  
      If Not ANDI.Connected Then Exit Sub ' Nope.
  
  
      Dim result As Boolean
  
      result = message.Contains("DIS")
      If result Then  &lt;&lt;'this is my DIS string to determine which event will be handled**
          dispenser()
      End If
  
  
  
      ' Did the user type anything?
      If message = "" Then Exit Sub ' Nope.
  
  
  
  
  
      ' Send the contents of the text box.
      MyResult = ANDI.SendMessage((message))
  
  
  
      'System.Threading.Thread.Sleep(1000)
      Console.WriteLine("result: " &amp; MyResult)
      'MsgBox("my result: " &amp; MyResult)
      ' How did we do?
      If MyResult Then
          If target = 1 Then
              Console.WriteLine("Message Sent 1")
          Else
              Console.WriteLine("Message Sent else")
          End If
      Else
          Beep()
          If target = 1 Then
              Console.WriteLine(ANDI.StatusMessage)
          Else
              Console.WriteLine(ANDI.StatusMessage)
          End If
      End If
  End Sub
  
   Sub Dispenser()
  
  
      Dim ManDis As String
      Dim DisCount As String
      Dim DisNum As String
      Dim DisDetail As String
  
      ManDis = Nothing
      DisCount = Nothing
      DisNum = Nothing
      DisDetail = Nothing
  
  
      ' ANDI Library access 
      ANDI = New ANDI_AXC
  
  
      'IP list for the console
      Dim addys As New List(Of String)
  
      addys.Add("10.0.99.139")
      addys.Add("10.0.99.138")
      addys.Add("10.0.99.181")
  
  
      For Each addy As String In addys
  
  
  
          With ANDI
              .DeviceClass = "POS01"
              .ServiceClass = "DGS"
  
              .CommPort = 1
              .EthernetPort = 6627
              .BaudRate = 9600
              .DataBits = 8
              .Parity = ANDI_AXC_LIBLib._PARITY_MODE.NO_PARITY
              .StopBits = 2
  
          End With
          Dim MyResult As ANDI_AXC_LIBLib.CONN_OP_RESULT ' The return value from Open (found in the type library)
  
  
          ANDI.DeviceID = addy
  
  
          ANDI.Close()
          ' Are we already connected?
          If ANDI.Connected Then
  
          Else
  
          End If
          ' Open the connection.
          MyResult = ANDI.Open()
          MsgBox(MyResult.ToString())
  
  
          Console.ReadLine()
          Call ANDI.Open()
  
  
  
  
          Console.WriteLine("You are connected to the NexGen at: " &amp; ANDI.DeviceID)
          MsgBox("You are connected!!!!")
          Console.WriteLine("")
  
  
  
          ManDis = returnedMessage.Substring(8, 3)&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; my error happens here.
          Console.WriteLine("Manufacturer = " + ManDis)
  
          'Device Name
          DisCount = returnedMessage.Substring(29, 2)
          Console.WriteLine("Device Name = " + DisCount)
  
          DisNum = returnedMessage.Substring(100, 2)
          Console.WriteLine("Device Name = " + DisNum)
  
  
          DisDetail = returnedMessage.Substring(29, 6)
          Console.WriteLine("Device Name = " + DisDetail)
  
  
          End
  
  
  
      Next
      Console.ReadLine()
  
  
  
  End Sub
  </code></pre>