Pros and Cons of Using Control ArraysA control array can significantly reduce the amount of code you have to write if several controls of the same type utilize the same or similar code routines. For example, consider a slide viewer program that displays multiple thumbnail images (in Image controls) on-screen and enables the user to click on an image to show it at full size. Without using a control array, the code for displaying each image in full size would have to be coded into each Image control's DblClick event. Putting all of the Image controls into a control array, however, requires coding only one Click event for the entire control array. Because the index number of the actual control that was clicked on is passed to the Click event, you can easily determine exactly which thumbnail image was selected and tailor your code to display that image in full size. Determining whether or not the use of a control array makes sense is easy. If multiple objects share the same or similar function (such as in the example above), it would probably be worth creating a control array. However, if individual controls have different functions and you would have to make exceptions in your code for them, a control array probably is not a good idea.
When using control arrays, you can reduce the amount of code necessary by a factor of however many controls are in your array. For example, if there are a dozen controls in your array, you may reduce the amount of code in your program to roughly a twelfth of what it would have been if you had to add the code for each control separately. There might be some overhead in the way of determining which control in the array on which to act (by examining the control index), but that is usually minimal. |
|
![]() |
![]() |
|||