Interactive PowerBasic Forum

IT-Consultant: Charles Pegge => OxygenBasic => Topic started by: Nicola on November 13, 2023, 11:39:47 PM

Title: Array Ubound problem
Post by: Nicola on November 13, 2023, 11:39:47 PM
Hi Charles,
Are there any problems with the ubound function?

I've tried this and it gives me some problems..

uses console
redim double a[5]

print "ubound of array: " ubound(a)

sub ff(double *d[])
===================
print "Test attributes of a passed dynamic array" cr cr
int i
print "dims: " tab dims(d) cr
print cr
print "ubound of array: " ubound(d)
end sub
'
'TEST:
ff a
wait
del a

This is the result I get:

ubound of array: 0
Test attributes of a passed dynamic array

dims:  1995979616

ubound of array: 0








http://forum.it-berater.org/index.php?msg=25169 (http://forum.it-berater.org/index.php?msg=25169)
Title: Re: Array Ubound problem
Post by: Charles Pegge on November 14, 2023, 04:57:03 AM
Hi Nicola,

It worked perfectly with multidimensional arrays. But I've now fixed it for 1d arrays:

PS:
Not quite!
My changes failed the self-compile test so I've withdrawn P9 until I have fixed the problem
Title: Re: Array Ubound problem
Post by: Nicola on November 14, 2023, 06:12:29 PM
In fact, Charles,
I was still having trouble and thought it was me who wasn't declaring the variables correctly... 
I was having incomprehensible results.
Thank you for your valuable help.
Good luck with your work.

I'm looking forward to the new P9.

Cheers
Title: Re: Array Ubound problem
Post by: Nicola on May 02, 2024, 03:45:00 PM
Hi Charles.
Could you please update me on the progress related to the Arrays?
Ubound? and other related commands working properly now?

Thank you very much.
Title: Re: Array Ubound problem
Post by: Charles Pegge on May 03, 2024, 10:57:58 AM
Ubound etc last tested in March. Should be ok now.
Title: Re: Array Ubound problem
Post by: Nicola on May 03, 2024, 11:01:59 AM
very good.  :)
In fact, I wasn't making use of arrays while waiting for news.
Thank you Charles.
Title: Re: Array Ubound problem
Post by: Zlatko Vid on May 03, 2024, 06:13:48 PM
I must ask ..why you need Ubound
i never use it and i don't see purpose of that even some QB64 programeros
use them a lot ..same as REDIM ...omg ...maybe i am to limited or biased
to minimalism ... :D
Title: Re: Array Ubound problem
Post by: Theo Gottwald on May 04, 2024, 09:11:51 AM
Quote from: Zlatko Vid on May 03, 2024, 06:13:48 PMI must ask ..why you need Ubound
i never use it and i don't see purpose of that even some QB64 programeros
use them a lot ..same as REDIM ...omg ...maybe i am to limited or biased
to minimalism ... :D

Let me answer this.
Assume you hand over an ARRAY BYREF into a Function to do something with the Array Members.
How do yo ufind out if the Array is 0-based or 1-based and how large it is?
This is where LBOUND and UBOUND can help.
Title: Re: Array Ubound problem
Post by: Charles Pegge on May 04, 2024, 10:10:13 AM
To clarify:
You can reference an array using any indexbase - it does not have to be the original indexbase, the lbound and ubound will automatically adjust. They are particularly useful for dynamic arrays.
Title: Re: Array Ubound problem
Post by: Nicola on May 04, 2024, 10:40:37 AM
Good morning.
For me the use of vectors or matrices are very important. Since I was in school I learned how to use them and I stuck with them.
As Charles has shown through the examples in... demos\math, are very useful...
Title: Re: Array Ubound problem
Post by: Zlatko Vid on May 05, 2024, 04:16:31 PM
QuoteHow do yo ufind out if the Array is 0-based or 1-based and how large it is?

easy
indexbase ..you define yourself
sizeOf() return array size
Title: Re: Array Ubound problem
Post by: Charles Pegge on May 05, 2024, 05:41:57 PM
Indexbase can be  read as well as set:
print indexbase

sizeof only works for elements, not arrays in o2
Title: Re: Array Ubound problem
Post by: Zlatko Vid on May 05, 2024, 06:49:05 PM
and for what is spanof()

ahh yes ...spanof() seems that work  ;)
ye i remember, i use it few times .

'quick test
int arr[1000]

print spanof(arr)