Runing Text

Do not Click

Dynamic Array

Saturday, 16 January 2010 , Posted by Andi at 03:25

If the size or the number of array elements is not known, then the array variable can be declared as an array of dynamic arrays. Understanding the dynamic array is a list or set of data with the same data type, stored in a given index variable to distinguish each member of the array where the number of elements or the amount of data stored in the array is dynamic or changing during the program starts. To declare a dynamic array can be written with the following syntax:

Dim SetArray() as DataType



From the above syntax can be seen that the size of the array or the amount of data has not been determined. To provide input data, then the very first thing to do is change the size (resize) with syntax redim (which comes from the word redimension).

Example :

1. Dim arrName() as String
2. Redim arrName(8)


Description:
In the example above; lines used to create a dynamic array with the name arrNama, while the second row using redIm to resize the array to be 9 elements (starting from index 0 to index 8).

Weaknesses using redIm is dipanggial commands every time, all the values in the previous elements will be lost. To overcome this, create a preserve for VB add an array element without deleting the previous value.

Example:

Dim NameArray(5) as Integer
NameArray(3) = 80
Msgbox (NameArray(3)) ‘The program will display the number 80
Redim Preserve NameArray(10)
Msgbox (NameArray(3)) ‘ The program will display the same number 80...

Currently have 0 komentar:

Leave a Reply

Post a Comment

Related Post