ARRAY(arglist)

Returns an array containing the given values (Variant).


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

REMARKS
* This can only be used when the array is declared with a Variant data type (As Variant).
* This array is always 0 based.
* This function ignores any Option Base 1 statements.
* 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 learn.microsoft.com

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

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

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

Sub Testing2()
Dim aValues(4) As Integer 'declares starting at zero

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

   Debug.Print aValues(0) '= 1
   Debug.Print aValues(1) '= 2
   Debug.Print aValues(2) '= 3
   Debug.Print aValues(3) '= 4
   Debug.Print aValues(4) '= 0
   
   Stop 'open the Locals window
'notice that aValues(4) exists and is 0
End Sub

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