p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   VB.NET 2002/2003 Basics (http://p2p.wrox.com/forumdisplay.php?f=76)
-   -   Searching ArrayList (http://p2p.wrox.com/showthread.php?t=200)

Mike2000 June 5th, 2003 02:02 PM

Searching ArrayList
 
Having problem in search of arraylist, following is the explanation.

Following is the contact class:

Public class contact()
  LastName as string
  FirstName as string
  Age as integer
End Class

I created a arraylist name as a1 and stores contact info in it.

dim a1 as arraylist
a1.Add(New contact(lastname,firstname,age))

Have following Search Criteria for user:

Name contains:
age:

Would like to search what ever user entered in the Name contains and age input. (e.g: if user enterd "A" as name contains and 28 as age, search would bring all the contacts which have "A" in either first or last name with age 28)

Question is Could "IndexOf" be used to search(like the above criteria) in arraylist of objects(contacts)? and if so any hint would be apprecitated.

Thanks,

Phillip June 10th, 2003 03:06 AM

Mike,

What you can do is iterate (For Each.....Next) through the items in the arraylist.

As you go through each one, check the age, if it is the correct age then check the name.

You can get the IndexOf property if both checks are good and then enumerate to the next item.

You can then use your IndexOf property to access the items in the arraylist.

BUT REMEMBER, if you remove an item then the IndexOf of other items WILL change.

Hope this helps :)



Quote:

quote:Originally posted by Mike2000
 Having problem in search of arraylist, following is the explanation.

Following is the contact class:

Public class contact()
  LastName as string
  FirstName as string
  Age as integer
End Class

I created a arraylist name as a1 and stores contact info in it.

dim a1 as arraylist
a1.Add(New contact(lastname,firstname,age))

Have following Search Criteria for user:

Name contains:
age:

Would like to search what ever user entered in the Name contains and age input. (e.g: if user enterd "A" as name contains and 28 as age, search would bring all the contacts which have "A" in either first or last name with age 28)

Question is Could "IndexOf" be used to search(like the above criteria) in arraylist of objects(contacts)? and if so any hint would be apprecitated.

Thanks,




All times are GMT -4. The time now is 04:31 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.