[VB learning] 4: array and structure

xiaoxiao2021-03-06  43

Static one-dimensional array

DIM array name (subscript) [AS type]

Description:

(1) The subscript must be constant and cannot be an expression or variable.

(2) The minimum of -32768 below the subscript is 32767.

(3) omitting the lower bound, its default is 0, the size of the one-dimensional array is: upper bound - lower bound 1.

Static multidimensional array

DIM array name (subscript 1 [, subscript 2 ...]) [AS type]

Description:

(1) The number of subscripts determines the dimension of the array and up to 60 dimensions.

(2) The size of the array = the product of each dimension.

Dynamic array

Redim array name (subscript 1 [, subscript 2 ...] [AS type]

Description:

(1) The subscript in the dynamic array REDIM statement can be constant, or there may be a variable with a certain value.

(2) You can change the size of the array in the process, or change the number of dimensions of the array.

(3) Each time you use the RedIM statement, you will lose the value in the original array. You can add the preserve parameter after the redim statement, you can retain data in the array, but use Preserve can only change the size of the last dimension, and the front of several dimensions cannot be changed. .

Array assignment

(1) Using the loop structure

DIM A (1 to 10) AS Integer

FOR i = 1 to 10

A (i) = 0

Next I

(2) Utilize the array function

Dim A As Variant, B As Variant'dim A () AS VARIANT, B () 'must be variable, can define a dynamic array

A = array (1, 2, 3, 4, 5)

B = Array ("ABC", "DEF", "67")

(3) Assign a value of an array to another array directly

DIM A (3) AS INTEGER, B () AS INTEGER'DIM A (3) AS Interger, B 'Only these two definition forms can be assigned normally

A (0) = 2: a (1) = 5: a (2) = - 2: a (3) = 2

B = a

Description:

(1) The data type on both sides of the assignment must be consistent.

(2) If the assignment number is a dynamic array, the system is assigned when the system automatically converts the dynamic array redim into an array of the same size.

(3) If the value left is a size fixed array, the array assignments.

Control array

(1) The control array identifies the controls by index (index in the attribute), and the first subscript is 0. Such as: text1 (0), Text1 (1), Text1 (2), Text1 (3) ......

(2) When programming, add the remaining elements through the LOAD method, or you can delete a given element by unload.

(3) Each added control array determines its location on the form through the LEFT and TOP properties, and sets the Visible to TRUE.

Custom data type

TYPE Custom Type Name

Element name [(subscript)] AS type name

......

Element name [(subscript)] AS type name

End Type

Using the form: DIM Variable Name AS Custom Type Name-defined type representation method: variable name. Element name

Description:

(1) The custom type is generally defined in the standard module (.bas), the default is public.

(2) The element in the custom type can be a string, but it should be a fixed length string.

(3) The custom type name cannot be confused with the variable name of the type.

(4) Note the difference in custom type variables and arrays: They are consisting of several elements. The elements of the former represent different natures, different types of data, represent different elements in element name; the latter stores the same nature, the same Type data, the following marked represents different elements.

(5) The same custom type variable can be assigned directly, and the custom type array is that each element in the array is a custom type.

转载请注明原文地址:https://www.9cbs.com/read-75927.html

New Post(0)