<< Prev        Next >>

ID : 5070

Array

Function

To create variant type array.

Syntax

Array(value list)

Guaranteed entry

Value list
Designate the value list separated by a comma (,). The designated value is stored as an array element. You can also designate a value of different data type.

Return value

Return variant type array.

Description

  • To refer to an array element, place brackets following a variable name and designate an index number of the element in the brackets.
    Index number is numbered sequentially starting from 0. In the following example, the third element "30" will be output.
Dim A As Variant
A = Array(10,20,30)
PrintDbg A(2)  '30 is output
  • If the index number is out of range, 8160800C error will occur at the execution.
  • When you use a variable for a value of the value list, the value which is evaluated will be used at the program execution.

Related Terms

Array

Attention

  • You can define an array in the array. It is called Jagged array. To access a jagged array, you need to access indirectly through Variant variable like the following example.
Dim a As Variant
Dim b As Variant
a = Array( Array(0,1,2) , Array(3,4) ) ' Create jagged array
b = a(0) ' Acquire Array(0,1,2)
PrintDbg b(0), b(1), b(2) ' 0,1,2 are output
b = a(1) ' Acquire Array(3,4)
PrintDbg b(0), b(1) ' 3,4 are output

As an example below, accessing directly causes compile error in PacScript.

Dim a As Variant
a = Array( Array(0,1,2) , Array(3,4) ) ' Create jagged array
PrintDbg a(0)(0), a(0)(1), a(0)(2) 'Error

Example

In the following example, corresponding list for colors and codes will be output.

Pro1.pcs
Sub Main
  Dim n As Integer
  Dim vColor As Variant
 vColor = Array( "RED", &H0000FF, "GREEN", &H00FF00, "BLUE", &HFF0000 )

  For n=0 To Ubound(vColor)
     PrintDbg vColor(n*2),  Hex(vColor(n*2+1))
  Next

End Sub

ID : 5070

<< Prev        Next >>