数组精华(Array essence).docVIP

  • 5
  • 0
  • 约9.68千字
  • 约 16页
  • 2017-10-07 发布于河南
  • 举报
数组精华(Array essence)

数组精华(Array essence) Declare array The array declaration is the same as other variables, which can be declared using Dim, Static, Private, or Public statements. Scalar variables (non arrays) differ from array variables in that they usually have to specify the size of the array. If the size of the array is specified, it is a fixed size array. If the size of an array can be changed when the program is running, it is a dynamic array. Whether the array is indexed from 0 or 1 is based on the setting of the Option Base statement. If Option Base is not specified as 1, then the index of the array starts from zero. Declare a fixed size array The following line of code declares a fixed size array, which is a Integer array of 11 rows multiplied by 11 columns: Dim MyArray (10, 10) As Integer The first parameter represents the row; the second parameter represents the column. Like the declarations of other variables, the data type of the element in the array is declared to be Variant, unless a data type is specified. The numeric Variant element of each array in the array occupies 16 bytes. Each string type Variant element occupies 22 bytes. To make the written code as concise as possible, you must explicitly declare the array as a data type, not a Variant. The following lines of code compare the sizes of several different arrays: An integer array uses 22 bytes (11 elements * 2 bytes) ReDim MyIntegerArray (10) As Integer double precision array uses 88 bytes (11 elements * 8 bytes). ReDim MyDoubleArray (10) As Double An array of variants uses at least 176 bytes (11 elements * 16 bytes). ReDim MyVariantArray (10) The integer array uses 100 * 100 * 2 bytes (20000 bytes). ReDim MyIntegerArray (99, 99) As Integer double precision array uses 100 * 100 * 8 bytes (80000 bytes). ReDim MyDoubleArray (99, 99) As Double An array of variants uses at least 160000 bytes (100 * 100 * 16 bytes). ReDim MyVariantArray (99, 99) The maximum value of an array variable is based on how much memory is avai

文档评论(0)

1亿VIP精品文档

相关文档