Array: – A standard structure for storing data in any programming language is an array. Whereas an individual variable can hold only single entity, such as a number, data and string. Array can hold sets of related data. There are two types of array used in visual basic programming. They are called variable array and control array.
Variable array: – Variable array is similar to other programming language. The variable array can be used to store large amount of single data type in memory location. Variable array can be declare in memory before using a bit for storing data. There are two type of variable array can be used in visual basic programming. They are called one–dimension variable array and multi–dimension variable array.
Syntax of one-dimension variable array is –
Dim <Array Name> ([<Lower> To] <Upper>) As <Data Type>
The square bracket and angle bracket are not part of dim statement. The square bracket indicate that this part is optional and angle bracket indicate that this part is mandatory array name is the name of the variable array. Lower is the value of the arrays lowest subscript. It is optional, but its value must be zero or more. Value of lower item must be less than the value of upper item. If it is not define, it is automatically assign to zero. Upper is the value of the arrays highest subscript and the data type is a visual basic data type.
Syntax of the two dimension array is –
Dim <Array Name> ([Lower> To] <Upper>, [<Lower> To] <Upper>) As <Data Type>
A two dimensional array is like an array of arrays and can be used to hold multiple set of value. It is best to think of a two dimensional array as a having rows and columns. To declare two dimensional array, two set of subscript are required, the first one for rows and the second one for columns. Lower value of both rows and column subscript are optional but its value must be zero or more. If they not defined, treated as zero. And upper value is mandatory and it must be greater than the lower value.
Control array: – A control array is a group of control, all of the same type. The control array has a name, but the individual controls in the array do not.
Even though a control array only has one name, the control in it may be access and used at individual controls. This is possible because each control is assigned a number known as an index. An index is used to pin point a specific control with in a control array. The first control in an array is assigned the index zero, the second control is assigned as one and show on.
All of the controls the control array share the same event procedure. Because of this it is offend easier to write a code for a control array than it is for individual control.
Creating control array: – There are two way to create an array control –
- Create the individual controls more than one time, then change name of first control using the name properties. When we select another control, and change same name, visual basic will display an alert message and two button appear with this alert message. If user click of button, a control array created for that individual control. Now user change name for remaining other individual controls. The above message will not appear next time and control array created.
- Another way to create a control array and change name of that control we wish to give the control array. Copy the control to the clipboard. Past the copy of that control on to the form. Visual basic alert us that we have already a control with the same name and asks us if we wish to create a control array.