Page 1 of 1 1
Topic Options
#81273 - 2002-09-19 05:47 PM Improved UBOUND
Sealeopard Offline
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
#81274 - 2002-09-19 06:36 PM Re: Improved UBOUND
Breaker Offline
Hey THIS is FUN
*****

Registered: 2001-06-15
Posts: 268
Loc: Yorkshire, England
In this case, however, you'd need to do:
code:
Dim $b[1,2,3,4]
$dimensions = Ubound(Ubound($b)) + 1

..to obtain the number of dimensions in an array.

I like it, though.
_________________________
================================================
Breaker


Top
#81275 - 2002-09-19 06:41 PM Re: Improved UBOUND
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
However, the point is that I need some kind of way to figure out the number of dimensions that an array might have. Using UBOUND might be the easiest way since you get both the number of dimensions and the dimension sizes in just one query.
_________________________
There are two types of vessels, submarines and targets.

Top
#81276 - 2002-09-19 07:21 PM Re: Improved UBOUND
Lee Wilmott Offline
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
#81277 - 2002-09-19 07:34 PM Re: Improved UBOUND
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Since the support for multi-dimensional array was only recently introduced, I don't think we'll have a compatibility issue since we're only changing the behavior for array with more than one dimension. For arrays with only one dimension UBOUND will work as usual.
_________________________
There are two types of vessels, submarines and targets.

Top
#81278 - 2002-09-19 11:09 PM Re: Improved UBOUND
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
mmm...

there should be easier way...

new function Mubound, Mbound or something...
or just ubound($array[])

just to keep it simple as possible.
_________________________
!

download KiXnet

Top
#81279 - 2002-09-19 11:14 PM Re: Improved UBOUND
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
How about Moribund() ???
Top
#81280 - 2002-09-20 12:32 AM Re: Improved UBOUND
kholm Offline
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
#81281 - 2002-09-20 04:51 AM Re: Improved UBOUND
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
If you pass an array into a UDF, then the UDF does not know about the size of the array. I was going to rewrite some of my array function in order to support multi-dimensional arrays and thus I'd like to have a build-in function of some sorts that returns the dimensions of an array.

Also, you can only REDIM the right-most dimension, it is a limitation in the underlying API.

[ 20. September 2002, 04:52: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#81282 - 2002-09-20 08:32 AM Re: Improved UBOUND
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
and not only in functions...

if you have scripts doing for each split and joins inside each other multiple times and have some logic there you may loose the arrays dimension count.
_________________________
!

download KiXnet

Top
Page 1 of 1 1


Moderator:  Lonkero, ShaneEP, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 857 anonymous users online.
Newest Members
JimDunn, fgarcia, Viginette, ManuvdWielNL, Sir_Barrington
17890 Registered Users

Generated in 0.057 seconds in which 0.022 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org