VBScript Learning notes-arrays

Source: Internet
Author: User

Array declaration
Dim var (ten)

the array declaration indicates the maximum value of the array name and index (index). The array index starts at 0. So the statement creates an array of 11 elements, where the value is var (0), VAR (1), ... and VAR (10)

Iterate through all elements of an array

You can use the For Each loop without specifying the number of elements in the array beforehand. This method does not apply if you do not want to process each element of the array.

You can also iterate through the array by indexing each value sequentially.

The following shows each of these two ways.

Dimvar5) Var (0) =0var (1) =1var (2) =2'fewer items are used than the number of elements in the arrayNitems =3 for  eachValueinchvar wscript.echo valueNext fori =0  toNitems-1wscript.echo var (i)Next

The output is as follows


0
1
2



0
1
2

Since the array actually has 6 elements, but only three of them are initialized, and when the array is traversed in the first way, the uninitialized array elements are traversed, and the output has three lines of whitespace.

Variable-size arrays

If necessary, set the array so that it is variable in size. First, you do not have to specify the size when declaring an array

Dim VarName ()

You can use the ReDim statement to set or reset the size of an array before the first use, and at any time thereafter

ReDim [Preserve] varname (subscripts) [, ...]

The keyword Preserve makes VBScript keep existing data in a resized array. (If the new array is shorter than the original, the extra elements at the end are removed). If there is no preserve, the declared variable and all elements are set to nothing

VBScript Learning notes-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.