Wiki source for KeyPgLbound


Show raw source

{{fbdoc item="title" value="LBOUND"}}----
Returns the lower bound of an array's dimension

{{fbdoc item="syntax"}}##
[[KeyPgDeclare|declare]] [[KeyPgFunction|function]] **Lbound** ( array() [[KeyPgAs|as]] [[KeyPgAny|any]], [[KeyPgByval|byval]] //dimension// [[KeyPgAs|as]] [[KeyPgInteger|integer]] = 1 ) [[KeyPgAs|as]] [[KeyPgInteger|integer]]
##
{{fbdoc item="usage"}}##
//result// = **Lbound**( //array// [, //dimension// ] )
##
{{fbdoc item="param"}}
##//array//##
an array of any type
##//dimension//##
the dimension to get lower bound of

{{fbdoc item="ret"}}
Returns the lower bound of an array's dimension.

{{fbdoc item="desc"}}
##**Lbound**## returns the lowest value that can be used as an index into a particular dimension of an array.

Array dimensions are numbered from one (##1##) to ##//n//##, where ##//n//## is the total number of dimensions. If ##//dimension//## is not specified, ##**Lbound**## will return the lower bound of the first dimension.

If ##//dimension//## is zero (##0##), ##**Lbound**## returns ##1##, corresponding to the lower bound of the array dimensions ##1##..##//n//##. ##**Ubound**## returns ##//n//##, the number of dimensions, in this case. This can be used to detect the array's number of dimensions.

For any other (non-zero) ##//dimension//## values outside of the valid range ##1##..##//n//##, ##**Lbound**## returns ##0##. ##**Ubound**## returns ##-1## in this case. This can be used to detect whether a certain dimension exists in the array, and also works when used on an empty array which does not have any valid dimensions.

Thus, for empty dynamic arrays, we get:
- ##Lbound(array) = 0## and ##Ubound(array) = -1## (dimension 1 does not exist)
- ##Lbound(array, 0) = 1## and ##Ubound(array, 0) = 0## (zero dimensions)
- ##@array(Lbound(array)) = 0## (no data buffer allocated)

{{fbdoc item="ex"}}
{{fbdoc item="filename" value="examples/manual/array/lbound.bas"}}%%(freebasic)
dim array(-10 to 10, 5 to 15, 1 to 2) as integer

print lbound(array) 'returns -10
print lbound(array, 2) 'returns 5
print lbound(array, 3) 'returns 1
%%

{{fbdoc item="see"}}
- ##[[KeyPgUbound|Ubound]]##
- ##[[KeyPgStatic|Static]]##
- ##[[KeyPgDim|Dim]]##
- ##[[KeyPgRedim|Redim]]##

{{fbdoc item="back" value="CatPgArray|Array Functions"}}
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode