"vba programming" 08. Arrays

Source: Internet
Author: User

"introduction to arrays"
An array is actually an ordered set of data of the same type, and its image is represented as a linear table. When storing data, a contiguous storage space is first allocated in memory, and each element is stored sequentially in contiguous storage cells.
"define Static array"
Dim Data group (the Upper and lower bounds of the data element,...) As data type
Dim a (ten) as Integer ' whose array is named a whose subscript starts at 0, the lower bound is a (0) to a (10) of the accessible elements in the 10 period.
Dim b (1 to Ten) as Double ' accessible element a (1) to a (10)
"Tips"
(1) dimension of multidimensional arrays up to 60 dimensions
(2) when using a static array, you must indicate the upper and lower bounds of the array and the number of dimensions of the array, and the bounds of the array must use constants, cannot use the variable
(3) each array element can store only one data
"code area"

Private SubArray Initialization ()DimYunnan (1  to 4) as StringYunnan (1) ="Kunming"Yunnan (2) ="Qujing"Yunnan (3) ="Zhaotong"Yunnan (4) ="Dali"Yunnan (4) ="Yuxi"     for  eachCityinchYunnan Debug.Print cityNextEnd Sub

"execution results"

"two-dimensional Static array"
"code area"

Private SubMatrix Assignment ()DimI as Integer    DimJ as Integer    DimA1  to 3,1  to 5) as Integer    'Use the product of I and J to fill in an array     fori =1  to 3      forj =1  to 5a (i, j)= i *JNextJNextI fori =1  to 3      forj =1  to 5Debug.Print"A ("& I &", "& J &")="& A (i, J) &Space(5); NextJ Debug.PrintNextIEnd Sub

"results show"

"two-dimensional Dynamic array"
Dim array name () as data type
Dim a () as Double

"code area"

Private SubArray Assignment ()DimA1  to 3) as Integer    Dimb () as Integer    DimI as Integer    'Initialize the value in array a     fori =1  to 3a (i)=INextb=a'Print the value of a arrayDebug.Print"the value of the A array is:"Debug.Print"a (1) ="& A (1) Debug.Print"a (2) ="& A (2) Debug.Print"a (3) ="& A (3)        'prints the value of the B arrayDebug.Print"The value of the B array is:"Debug.Print"b (1) ="& B (1) Debug.Print"b (2) ="& B (2) Debug.Print"b (3) ="& B (3)End Sub

"results show"

"vba programming" 08. Arrays

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.