Prev: Array of pointers
Next: Will this object get destroyed?
From: dpb on 11 Oct 2009 10:00 MikeD wrote: > > > "dpb" <none(a)non.net> wrote in message > news:har6dm$cet$1(a)news.eternal-september.org... >> xytsrm wrote: >>> Does anyone know if there is a function that returns the size of a >>> ReDim'ed single dimension array? >> >> UBound() > > > Not really quite that simple. ... > > You should use UBound() - LBound + 1 Left as "Exercise for the student"... Seemed enough of a hint to me... :) --
From: xytsrm on 11 Oct 2009 10:11 I ran a simple test of UBound(): Dim A(10) As String Dim B() As String Sub Main() ReDim B(15) MsgBox "UBound(A): " & UBound(A) & vbCrLf & "UBound(B): " & UBound(B) End Sub UBound(A) returned 10 and UBound(B) returned 15. If the lower bound default is 0, and as I have not affected the lower bound, then apparently UBound() returns the number of elements not the index. X. "MikeD" wrote: > > > "dpb" <none(a)non.net> wrote in message > news:har6dm$cet$1(a)news.eternal-september.org... > > xytsrm wrote: > >> Does anyone know if there is a function that returns the size of a > >> ReDim'ed single dimension array? > > > > UBound() > > > Not really quite that simple. UBound() by itself only does it if the lower > bound is 1. Since the default lower bound of an array is 0, that's what > most commonly used, so if the upper bound is 10, then there's really 11 > elements in the array. > > You should use UBound() - LBound + 1 > > -- > Mike > > >
From: dpb on 11 Oct 2009 10:16 xytsrm wrote: > I ran a simple test of UBound(): .... > If the lower bound default is 0, and as I have not affected the lower bound, > then apparently UBound() returns the number of elements not the index. No, it's still the upper bound and there are 16 elements in the array -- count 'em from 0 - thru 15 --> ??? Mess w/ Option Base and see what happens. Also, please don't top post--makes follow conversation hard... --
From: xytsrm on 11 Oct 2009 11:05 dpb, Are you trying to say that ReDim A(10) is actually creating 11 elements 0-15? X. "xytsrm" wrote: > Thanks everyone. > > I'm actually just looking for the current index, not the number of bytes, so > UBound should work. > > X. > > > "xytsrm" wrote: > > > Does anyone know if there is a function that returns the size of a ReDim'ed > > single dimension array? > > > > X. > >
From: xytsrm on 11 Oct 2009 11:21
dpb your right! I didn't read the discription of ReDim correctly. I thought ReDim() was dimensioning an absolute number of elements - its actually dimensioning the subscript, so the actual number of elements is one more then the ReDim(). X. "xytsrm" wrote: > dpb, > > Are you trying to say that ReDim A(10) is actually creating 11 elements 0-15? > > X. > > > "xytsrm" wrote: > > > Thanks everyone. > > > > I'm actually just looking for the current index, not the number of bytes, so > > UBound should work. > > > > X. > > > > > > "xytsrm" wrote: > > > > > Does anyone know if there is a function that returns the size of a ReDim'ed > > > single dimension array? > > > > > > X. > > > |