Page 179 - Open Soource Technologies 304.indd
P. 179
Unit 7: Arrays in Visual Basic
Comments
1. Using a subscript greater than the upper bound of an array is not allowed. For instance,
the following lines of code produce the error dialog box shown immediately thereafter:
2. Dim trees() As String = {“Sequoia”, “Redwood”, “Spruce”}
3. txtBox.Text = trees(5)
4. If arrayOne() and arrayTwo() have been declared with the same data type, then the state-
ment
arrayOne = arrayTwo
makes arrayOne() an exact duplicate of arrayTwo(). It will have the same size and contain
the same information.
5. An array can require a large block of memory. After the array is no longer needed, the
statement Erase array name can be executed to release all memory allocated to the array.
7.3 Control Array
Control arrays can be created at run time using the statements
• Load object (Index %)
• Unload object (Index %)
Where object is the name of the control to add or delete from the control array. Index % is the
value of the index in the array. The control array to be added must be an element of the existing
array created at design time with an index value of 0. When a new element of a control array
is loaded, most of the property settings are copied from the lowest existing element in the array.
Following example illustrates the use of the control array.
• Open a Standard EXE project and save the Form as Calculator.frm and save the Project as
Calculater.vbp.
LOVELY PROFESSIONAL UNIVERSITY 173