Skip to content

Array Functions

Array

Description

Returns an array.

Syntax

Array(arglist)

Arguments

  • arglist
    • A comma-delimited list of values that are assigned to the elements of an array contained with the Variant. If no arguments are specified, an array of zero length is created.
    • The notation used to refer to an element of an array consists of the variable name followed by parentheses containing an index number indicating the desired element.

Example

Dim Warehouses
Warehouses = Array("MAIN", "NORTH", "SOUTH")
UBound(Warehouses)   ' Returns 2 -- three elements, zero-based

Filter

Description

Returns a zero-based array containing a subset of a string array based on a specified filter criteria.

Syntax

Filter(inputstrings, value[, include[, compare]])

Arguments

  • inputstrings
    • One-dimensional array of strings to be searched.
  • value
    • String to search for.
  • Include
    • Optional. Boolean value indicating whether to return substrings that include or exclude Value.
    • If Include is True, Filter returns the subset of the array that contains Value as a substring.
    • If Include is False, Filter returns the subset of the array that does not contain Value as a substring.
  • compare
    • Optional. Numeric value indicating the kind of string comparison to use. The valid choices are:
Value Explanation
0 Binary comparison.
1 Textual comparison.

Example

' Narrow a list of warehouse codes to those containing
' "TH".
Dim All, Northern
All = Array("MAIN", "NORTH", "SOUTH")
Northern = Filter(All, "TH")
Join(Northern, ",")   ' Returns "NORTH,SOUTH"

Join

Description

Returns a string created by joining a number of substrings contained in an array.

Syntax

Join(list[, delimiter])

Arguments

  • list
    • A one-dimensional array containing substrings to be joined.
  • delimiter
    • Optional. String character used to separate the substrings in the returned string. If omitted, the space character (" ") is used. If delimiter is a zero-length string, all items in the list are concatenated with no delimiters.

Example

' Rebuild an item code from its parts.
Dim Parts
Parts = Split(%ItemCode, "-")
Join(Parts, "/")   ' "ACME-4471-BLU" returns "ACME/4471/BLU"

LBound

Description

Returns the smallest available subscript for the indicated dimension of an array.

Syntax

LBound(arrayname[, dimension])

Arguments

  • arrayname
    • The name of the array variable; follows standard variable naming conventions.
  • dimension
    • Optional. Whole number indicating which dimension's lower bound is returned. Use 1 for the first dimension, 2 for the second, and so on. If dimension is omitted, 1 is assumed.

Example

' Loop the whole of an array without assuming where it
' starts.
Dim Parts, i, Result
Parts = Split(%ItemCode, "-")
Result = ""
For i = LBound(Parts) To UBound(Parts)
  Result = Result & Parts(i)
Next
Result   ' "ACME-4471-BLU" returns "ACME4471BLU"

Split

Description

Returns a zero-based, one-dimensional array containing a specified number of substrings.

Syntax

Split(expression[, delimiter[, count[, compare]]])

Arguments

  • expression
    • A string expression containing substrings and delimiters.
    • If expression is a zero-length string, Split returns an empty array, i.e. an array with no elements and no data.
  • delimiter
    • Optional. String used to identify substring limits. If omitted, the space character (" ") is assumed to be the delimiter. If delimiter is a zero-length string, a single-element array containing the entire expression string is returned.
  • count
    • Optional. Number of substrings to be returned; -1 indicates that all substrings are returned. If omitted, all substrings are returned.
  • compare
    • Optional. Numeric value indicating the kind of comparison to use when evaluating substrings. The valid choices are:
Value Explanation
0 Binary comparison.
1 Textual comparison.

Example

' Item codes are supplier-part-colour. Take the part
' number.
Dim Parts
Parts = Split(%ItemCode, "-")
Parts(1)   ' "ACME-4471-BLU" returns "4471"

UBound

Description

Returns the largest available subscript for the indicated dimension of an array.

Syntax

UBound(arrayname[, dimension])

Arguments

  • arrayname
    • The name of the array variable; follows standard variable naming conventions.
  • dimension
    • Optional. Whole number indicating which dimension's upper bound is returned. Use 1 for the first dimension, 2 for the second, and so on. If dimension is omitted, 1 is assumed.

Example

' Guard against a short code before indexing into it.
Dim Parts
Parts = Split(%ItemCode, "-")
If UBound(Parts) >= 2 Then
  Parts(2)
Else
  ""
End If   ' "ACME-4471-BLU" returns "BLU"; "WIDGET-88" returns ""