ARRAY(arglist)

Returns an array containing the given values (Variant).


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

REMARKS
* 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.
* You can use the FILTER function to return an array containing a subset of a string array based on a filter condition.
* You can use the JOIN function to return a text string containing all the elements in an array.
* You can use the SPLIT function to return the array containing a specified number of substrings.
* For the Microsoft documentation refer to docs.microsoft.com

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