For i = LBound(ArrayName) To UBound(ArrayName) ... Next i
Using the For…Each Loop
The For…Each loop starts from the array index of 0.
1 2 3
For Each i In ArrayName ... Next i
All elements in a control array must be controls of the same type.
The controls in a control array have the same control name.
The controls in a control array can have different property values other than the name property.
The elements in a control array are distinguished by the Index property of the control, which ranges from 0 to 32767.
The indexes of the elements in a control array can be discontinuous.
All controls in a control array share the same event, and the event procedure name of a control array is followed by a pair of parentheses with an Index parameter inside to determine which control triggered the event.
Creating Control Arrays
By copying and pasting controls
When creating the first control, its Index property value is empty. When pasting a control:
The Index property value of the control before pasting is 0.
The Index property value of the pasted control is 1.
The Index of subsequent pasted controls is incremented by 1.
When creating the second control of the same type, specify the same control name as the first control.
When creating a control, modify the Index property.
Adding and Removing Elements in an Array
Adding an element to an existing control array
Before using the Load() method, create a control array in design mode. Elements added using the Load() method are not visible by default. The Visible property is set to False by default and needs to be manually set to True to display the elements. After adding an element, the Left and Top properties need to be set in order to modify the position of the element on the form.
Removing an element from an existing control array
Only controls added using the Load() method can be removed. Controls added in design mode cannot be removed.