Returns an array containing the given values (Variant).

arglistThe comma separated list of values (Array / Variant).

* This array is always 0 based.
* This function ignores any Option Base 1 statements and always creates an array that starts at 0.
* The subroutine "Testing1" demonstrates how to use this function.
* The subroutine "Testing2" demonstrates another way of creating a Fixed Array.
* If no arguments are given [vArray = Array()], then a zero length array is returned.
* A Variant that is not declared as an array can still contain an array.
* A Variant variable that contains an array is different from an array of elements with type Variant although the array elements are accessed in the same way.
* For the Microsoft documentation refer to

Sub Testing1() 
Dim vArray As Variant
'declares and populates the array
   vArray = Array(1, 2, 3, 4)

   Debug.Print vArray(0) '= 1
   Debug.Print vArray(1) '= 2
   Debug.Print vArray(2) '= 3
   Debug.Print vArray(3) '= 4

   Stop 'open the Locals window
'notice that vArray(4) does not exist
End Sub

Sub Testing2()
'declares a default empty array, starting at zero
Dim iArray(4) As Integer

'then populate the array
   iArray(0) = 1
   iArray(1) = 2
   iArray(2) = 3
   iArray(3) = 4

   Stop 'open the Locals window
'notice that iArray(4) exists and is 0
End Sub

© 2021 Better Solutions Limited. All Rights Reserved. © 2021 Better Solutions Limited Top