VB.net search ArrayList

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Mar 2008
Posts: 26
Reputation: TheFueley is an unknown quantity at this point 
Solved Threads: 0
TheFueley's Avatar
TheFueley TheFueley is offline Offline
Light Poster

VB.net search ArrayList

 
0
  #1
Jun 14th, 2009
How do you guys recommend searching an ArrayList for a specific string? My arraylist is defined as:
  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?
Rivera
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 710
Reputation: Teme64 will become famous soon enough Teme64 will become famous soon enough 
Solved Threads: 114
Teme64's Avatar
Teme64 Teme64 is offline Offline
Master Poster

Re: VB.net search ArrayList

 
1
  #2
Jun 14th, 2009
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
  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
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 26
Reputation: TheFueley is an unknown quantity at this point 
Solved Threads: 0
TheFueley's Avatar
TheFueley TheFueley is offline Offline
Light Poster

Re: VB.net search ArrayList

 
0
  #3
Jun 15th, 2009
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!
Rivera
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 26
Reputation: TheFueley is an unknown quantity at this point 
Solved Threads: 0
TheFueley's Avatar
TheFueley TheFueley is offline Offline
Light Poster

Re: VB.net search ArrayList

 
0
  #4
Jun 15th, 2009
That worked great. Thank you!
Rivera
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC