Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How can I count the number of items in an array?

0 views
Skip to first unread message

Steve Arbaugh

unread,
Dec 4, 1997, 3:00:00 AM12/4/97
to

Internetje wrote in message <348680...@solair1.inter.NL.net>...
>How can I count the number of items in an array? The array contains a
>list of salaries i.e. 20005, 30500, 36780, 40060
>
>Some people said that I should use Lbound and Ubound(???? What's that?
>The help file about Ubound/Lbound is missing)
>
>
>Joost


You would use the UBound function normally. UBound stands for upper bound
and refers to the upper limit of an array. If your array is 0 based and you
have 10 elements in it, the function x = UBound(myarray()) would return 9,
indicating that myarray(9) was the upper bound of the array, or you that you
have ten elements in the array (assuming that all the array items were
filled from 0 to 9).

HTH

Steve Arbaugh
ATTAC Consulting Group
web: http://ourworld.compuserve.com/homepages/attac-cg/acgsoft.htm
Reply Address adjusted to control spams remove leading ~ and NoSpm from
address
Send Replys to: ~75323...@NoSpm.Compuserve.com

Josh Kramer

unread,
Dec 6, 1997, 3:00:00 AM12/6/97
to

Just for clarity's sake it's worth pointing out that in order to dimension
an array with 10 elements you have to declare

dim x(9) not dim x(10) (unless you have specified Option Base 1 in your
module)

David Winters

unread,
Dec 6, 1997, 3:00:00 AM12/6/97
to

Here you go brother.

Dim intCounter As Integer
lngCount as Integer
lngCount = 0
For intCounter = LBound(arrayName) To UBound(arrayName)
If Not IsNull(arrayName(intCounter)) Then
lngCount = lngCount + 1
End If
Next intCounter
'lngCount = number of items in the array

Internetje wrote in message <348680...@solair1.inter.NL.net>...
>How can I count the number of items in an array? The array contains a
>list of salaries i.e. 20005, 30500, 36780, 40060
>
>Some people said that I should use Lbound and Ubound(???? What's that?
>The help file about Ubound/Lbound is missing)
>
>
>Joost

>ros...@awvn.nl

Ken Getz

unread,
Dec 6, 1997, 3:00:00 AM12/6/97
to

In article <01a8ea70$652e7ba0$308ad9cf@default>, jos...@earthlink.net
says...

> Just for clarity's sake it's worth pointing out that in order to dimension
> an array with 10 elements you have to declare
>
> dim x(9) not dim x(10) (unless you have specified Option Base 1 in your
> module)
>
>
Or unless you do the intelligent thing and dimension it as x(1 to 10),
and never have to worry about the start element again. I've wasted far
too much time debugging code which made the wrong assumption about the
start element... -- Ken

Bill McKnight

unread,
Dec 7, 1997, 3:00:00 AM12/7/97
to

Just for completeness, i.e. no assumptions.
LBound and Ubound have a second optional argument [dimension]

The dimension argument is a hole number indicating which dimension's lower
or upper bound is returned. Use 1 for the first dimension, 2 for the
second, and so on. If dimension is omitted, 1 is assumed.


David Winters wrote in message ...

0 new messages