title: visual basic array searching
body: <p>I'm trying to search an array for previous entries from a user inputted text box that match new incoming entries.  Is there any way to do this in Visual Basic?  I'm converting my code from C# and Visual Basic keeps giving me an error "Object reference not set to an instance of an object."   With this statement, the code skips the if block to check for matching text because arrayName(i) or 0 in this case is currently NOTHING.  If i take out this if block and it reaches the name check, then it causes an error because  there is nothing in arrayName(i) to convert to upper string.</p>
  
  <p>So here's my code..My question again was is there an easier way to search previous entries from an array to newly input entries.</p>
  
  <p>Edit: details</p>
  
  <p>This is the array declaration <code>Dim arrayName() = New String(2) {}</code> and when it gets to If arrayName(i).ToString.ToUpper = txtInput.Text.ToUpper Then it says "Object variable or With block variable not set." "NullReferenceException was unhandled by user code".  The "x" in the code is the fixed length of the array, which is 2 in this case.</p>
  
  <pre><code>Dim i As Integer = 0
              While x &gt;= i
                  If arrayName(i) IsNot Nothing Then
                      If arrayName(i).ToString.ToUpper = txtInput.Text.ToUpper Then
                          match = False
                          lblName.Text = "Enter a unique name"
                      End If
                  End If
                      i += 1
              End While
  </code></pre>