Friday, September 9, 2011

VBScript UBound & LBound

VBScript UBound & LBound
VBScript UBound function returns the largest subscript for a particular dimension of an array.

Syntax of VBScript UBound
UBound(arrayname[,dimension])

VBScript LBound function returns the smallest subscript for a particular dimension of an array.
The LBound for any dimension is ALWAYS 0.

Example 1 of VBScript UBound & LBound
Months=Array("Jan","Feb","Mar","Apr","May","Jun","Jul", "Aug", "Sept", "Oct", "Nov", "Dec")
Msgbox(LBound(Months))
Msgbox(UBound(Months))

Example 2 of VBScript UBound & LBound
Dim number(1,2)
number(0,0)="one"
number(0,1)="two"
number(0,2)="three"
number(1,0)="four"
number(1,1)="five"
number(1,2)="six"

Msgbox(LBound(number,1)) 'Shows 0
Msgbox(UBound(number,1)) 'UBound function returns the largest subscript for the indicated dimension of an array. 'Shows 1
Msgbox(LBound(number,2)) 'Shows 0
Msgbox(UBound(number,2)) 'Shows 2

Also See:
Complete List of VBScript Array Functions