Array Functions
Arrays in Visual Basic are very useful things to store a collection of variables or store records. Visual Basic allows any variable type to become an array.
Array([item], [nthitem])
Turns a list of arguments into an array
Example:
a() = Array("5","10","15","20")
MsgBox("My Number Is: " & a(3))
' A message box will popup with the text "My Number Is: 20"
IsArray([expr])
Returns a Boolean value that indicates if a specified variable is an array.
Example:
Dim a(3) as String
a(0) = "Blue"
a(1) = "Green"
a(2) = "Yellow"
IsArray(a)
' True
' Declare a single variable
Dim b as String
b = "Orange"
IsArray(b)
' False
Join(array, [delimiter])
Joins the array elements using the specified delimiter character(s)
Example:
Dim days() as String
Dim a as String
days() = Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat")
' The default delimiter for Join() is a space " ".
a = Join(days())
' a="Sun Mon Tue Wed Thu Fri Sat"
a = Join(days(), ",")
' a="Sun,Mon,Tue,Wed,Thu,Fri,Sat"
a = Join(days(), "##")
' a="Sun##Mon##Tue##Wed##Thu##Fri##Sat"
Split(string, [delimiter], [count], [compare])
Split a string into an array that contains the specified number of substrings. When count is ommited, splits into as many substrings as possible.
Example:
Dim days() as String
Dim a as String
a="Sun,Mon,Tue,Wed,Thu,Fri,Sat"
days() = Split(a, ",")
MsgBox(days(3))
' Wed
LBound(array)
UBound(array)
Returns the smallest subscript (or largest for UBound) for the specified array
These functions are very useful when you don't know the size of an array.
Example:
Dim a as String
days() = Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat")
a = LBound(days())
' a=0
a = UBound(days())
' a=6