Index Property (Control Array)

       

Returns or sets the number that uniquely identifies a control in a control array. Available only if the control is part of a control array.

Syntax

object[(number)].Index

The Index property syntax has these parts:

Part Description
object An object expression that evaluates to an object in the Applies To list.
number A numeric expression that evaluates to an integer that identifies an individual control within a control array.

Settings

The settings for number are:

Setting Description
No value (Default) Not part of a control array.
0 to 32,767 Part of an array. Specifies an integer greater than or equal to 0 that identifies a control within a control array. All controls in a control array have the same Name property. Visual Basic automatically assigns the next integer available within the control array.

Remarks

Because control array elements share the same Name property setting, you must use the Index property in code to specify a particular control in the array. Index must appear as an integer (or a numeric expression evaluating to an integer) in parentheses next to the control array name — for example, MyButtons(3). You can also use the Tag property setting to distinguish one control from another within a control array.

When a control in the array recognizes that an event has occurred, Visual Basic calls the control array's event procedure and passes the applicable Index setting as an additional argument. This property is also used when you create controls dynamically at run time with the Load statement or remove them with the Unload statement.

Although Visual Basic assigns, by default, the next integer available as the value of Index for a new control in a control array, you can override this assigned value and skip integers. You can also set Index to an integer other than 0 for the first control in the array. If you reference an Index value in code that doesn't identify one of the controls in a control array, a Visual Basic run-time error occurs.

Note   To remove a control from a control array, change the control's Name property setting, and delete the control's Index property setting.