#81273 - 2002-09-19 05:47 PM
Improved UBOUND
|
Sealeopard
KiX Master
   
Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
|
UBOUND returns the largest available subscript for an array dimension. If no dimension is specified, UBOUND should return the largest available subscripts for ALL dimensions if the array has multiple dimensions. For example
code:
dim $a[5], $b[1,2,3,4]
$sizea = ubound($a) $sizeb = ubound($b)
$sizea should have a return value of 5 and $sizeb should be an array of size 3 with $sizeb[0]=1, $sizeb[1]=2, $sizeb[2]=3, and $sizeb[3]=4 instead of just returning the size for the first dimension.
Thus, UBOUND could be used to determine the number of dimensions of an array.
_________________________
There are two types of vessels, submarines and targets.
|
|
Top
|
|
|
|
#81276 - 2002-09-19 07:21 PM
Re: Improved UBOUND
|
Lee Wilmott
Starting to like KiXtart
Registered: 2002-09-17
Posts: 106
Loc: Bristol, UK
|
Jens,
Wouldn't changing the UBound() function be a backwards compatibility issue?
Although I can see that returning the number of dimensions in an array would be very useful, wouldn't it have to be implemented as a separate function?
Also, in your example wouldn't the number of dimensions of your array $b be 4? I believe that your array $a should return a value of 1 - one dimension.
Maybe I'm getting the wrong end of the stick!
Lee
code:
Function NumOfDimensions($Array) $NumOfDimensions = 0 While UBound($Array, $NumOfDimensions + 1) <> -1 $NumOfDimensions = $NumOfDimensions + 1 Loop EndFunction
|
|
Top
|
|
|
|
#81280 - 2002-09-20 12:32 AM
Re: Improved UBOUND
|
kholm
Korg Regular
   
Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
|
Am i missing something here, or is this the hen before the egg ?
Can you use ReDim Preserve to add dimensions to an array, if not you should know the number of dimensions, you made the array yourself.
Can you ReDim one of the dimensions by choice, like ReDim Preserve Array[1], Preserve Array[2] This one should be possible according to the manual, but i havn't tested (understood the syntax)
Should this be valid for redimming the third dimension: ReDim Preserve ,, Preserve Array[2]
I like this solution for the UBound() function:
UBound($Array) Returnes number of members or number of dimensions
For multidimensions arrays, retrieve number of members in dimension 1: UBound($Array[0])
I belive the discussion could be how do we determine if the result from: UBound($Array) is number of dimensions or number of elements ?
I wil add a new suggestion for the function to determine the number of dimensions of an array: NumDim($Array) Should return 0 if $Array is not declared or not an array, otherwise 1.. to number of dims.
-Erik
|
|
Top
|
|
|
|
Moderator: Lonkero, ShaneEP, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart
|
0 registered
and 823 anonymous users online.
|
|
|