Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Collections-Removing-Counting

Status
Not open for further replies.

VbAche

Programmer
Nov 28, 1999
8
US
Hello,
Working on a little project. I have two text input boxes that retrieve StudentName, StudentId. I am able to add to the collection all new students. However, when I am removing a student through the use of a command button, cmdRemove, I receive an error involving invalid argument. I have set up a class with the function, which I use for my collection. Help !! In addition, I am unable to get the Count property to work at all. I need to be able to display in a label how many items in my entire student collection.

Any help, would be appreciated.

VbAche
 
Which argument do you use in the remove method? The argument can be either the position of the item or the item's key.

If you use whole numbers (such as StudentID ??) as keys, you must use CStr to convert them to strings before passing them to the Remove method.

Collection1.Remove CStr(StudentID)

If you use the position of an item, remember that this number is continuously re-evaluated as each item is removed. Which means that you have to remove them starting with the latest and ending at 1, as Collections are base 1 by default.

For intStudent = Collection1.Count To 1 Step -1
Collection1.Remove intStudent
Next intStudent
_________________________________
In theory, there is no difference between theory and practice. In practice, there is. [attributed to Yogi Berra]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top