See Also Example
Returns the smallest available subscript for the indicated dimension of an array
Syntax
LBound(array [,dimension])
Remarks
The LBound function is used with the UBound function to determine the size of an array. Use the UBound function to find the upper limit of an array dimension.
The LBound function has the following parts:
Part Description
array Name of an array variable.
dimension Integer indicating which dimension's lower bound is returned. Use 1 for the first dimension, 2 for the second dimension, and so on. If dimension is omitted, 1 is assumed.
LBound returns the values listed in the table below for an array with the following dimensions:
Dim A(1 To 100, 0 To 3, -3 To 4)
Statement Return Value
LBound(A, 1) 1
LBound(A, 2) 0
LBound(A, 3) -3
The default lower bound for any dimension is either 0 or 1, depending on the setting of the Option Base statement.
Arrays for which dimensions are set using the To clause in a Dim, Global, ReDim, or Static statement can have any integer value as a lower bound.
Dim Statement
Global Statement
Option Base Statement
ReDim Statement
Static Statement
UBound Function
The example uses the LBound function to determine the lower bounds for a three-dimensional array. To try this example, paste the code into the Declarations section of a form. Then press F5 and click the form.
Sub Form_Click ()
Dim A, B, C, Msg, NL, TB ' Declare variables.
Dim Array() ' Declare array variable.
NL = Chr(10): TB = Chr(9) ' Define newline, tab.
' Generate some random dimensions between 2 and 10 for array size.
A = -Int(9 * Rnd + 2) ' First dimension.
B = Int(9 * Rnd + 2) ' Second dimension.
C = Int(9 * Rnd + 2) ' Third dimension.
ReDim Array(A To 20, B to 20 , C to 20) ' Set dimensions.
Msg = "The test array has the following lower bounds: " & NL
Msg = Msg & TB & "Dimension 1 = " & LBound(Array, 1) & NL
Msg = Msg & TB & "Dimension 2 = " & LBound(Array, 2) & NL
Msg = Msg & TB & "Dimension 3 = " & LBound(Array, 3)
MsgBox Msg ' Display message.
End Sub