943,915 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 7816
  • VB.NET RSS
Jun 14th, 2009
0

VB.net search ArrayList

Expand Post »
How do you guys recommend searching an ArrayList for a specific string? My arraylist is defined as:
vb Syntax (Toggle Plain Text)
  1. Public Shared VisioSwitchArray As New ArrayList()
  2.  
  3. Public Structure switch
  4. Public HOSTNAME As String
  5. Public IP As String
  6. Public MODEL As String
  7. Public VLANS As String
  8. Public NEIs() As neighbor
  9. End Structure
  10.  
  11. Public Structure neighbor
  12. Public IFACE As String
  13. Public DIST_IP As String
  14. Public DIST_IFACE As String
  15. End Structure

What I'm trying to compare is the IP string from the switch structure and the DIST_IP string from the neighbor structure. Problem is, using VisioSwitchArray.contains(some_ip_address) always returns false. I'm guessing it is searching for a matching switch object with in the list right?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
TheFueley is offline Offline
28 posts
since Mar 2008
Jun 14th, 2009
1

Re: VB.net search ArrayList

Quote ...
I'm guessing it is searching for a matching switch object with in the list right?
That's right.

You can't use Contains method in this case. You have to loop and cast to find the right value
VB.NET Syntax (Toggle Plain Text)
  1. Dim i As Integer
  2.  
  3. For i = 0 To VisioSwitchArray.Count - 1
  4. If CType(VisioSwitchArray.Item(i), switch).IP = "10.0.0.2" Then
  5. ' Found
  6. Exit For
  7. End If
  8. Next i
Reputation Points: 218
Solved Threads: 201
Veteran Poster
Teme64 is offline Offline
1,024 posts
since Aug 2008
Jun 15th, 2009
0

Re: VB.net search ArrayList

Sweet! I will give it a try. In the mean time, I used a loop to String.Compare each item. Not what I wanted though. Thanks for the tip!
Reputation Points: 10
Solved Threads: 0
Light Poster
TheFueley is offline Offline
28 posts
since Mar 2008
Jun 15th, 2009
0

Re: VB.net search ArrayList

That worked great. Thank you!
Reputation Points: 10
Solved Threads: 0
Light Poster
TheFueley is offline Offline
28 posts
since Mar 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: TabPage Image + DrawItem
Next Thread in VB.NET Forum Timeline: Which HTML Element is clicked in WEBBROWSER CONTROL





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC