Visual Basic - Objects
- Collections
Properties
Methods
An alternative to Arrays
VB4: not Controls - >Control Array
Collections - Properties: Count
Collections - Methods: Add, Remove, Item
| Collection.Add Item, [Key], [Before], [After] | ||||||||
|
| Dim MyNames as New Collection For i = 1 To 20 MyNames.Add "Name" & i, "Key#" & i Next Print MyNames(3) Print MyNames("Key#4") |
| Collection.Remove Index | Key | ||||
|
| Dim MyNames as New Collection ' Remove all elements (1) For i = 1 To MyNames.Count MyNames.Remove 1 'the element index is adjusted after removal Next |
| Dim MyNames as New Collection ' Remove all elements (2) For Each x in MyNames MyNames.Remove 1 Next |
| Collection.Item(index) | ||
|
| Dim Things As New Collection --- Print Things.Item(3) Print Things(4) '.Item is default method |