Size Of Arrays

Just starting out? Need help? Post your questions and find answers here.
PureNewbie
New User
New User
Posts: 2
Joined: Fri Aug 08, 2008 12:56 pm
Location: United Kingdom

Size Of Arrays

Post by PureNewbie »

If you don't know in advance, does PureBasic have a method of obtaining the number and range of items in an array? The tools I am used to (VB6, VBScript etc) are LBound and UBound, but PureBasic doesn't seem to have these.

I understand that PureBasic can use linked lists and collections instead of simple one dimensional arrays, so this is probably just me trying to get a job done the wrong way.

Any help (or redirection) would be great.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

lbound is always zero for PB arrays.

Rumour has it that a forthcoming version of PB will have a cross-platform function for retrieving ubounds of individual array dimensions. In the meantime you can use PeekL(arrayName()-8 ) to get the total number of elements.
I may look like a mule, but I'm not a complete ass.
Thalius
Enthusiast
Enthusiast
Posts: 711
Joined: Thu Jul 17, 2003 4:15 pm
Contact:

Post by Thalius »

for now either in a macro or however you like it:

Getting the Size of an Array():

Code: Select all

PeekL(@Array() - 8)
Cheers,
Thalius
"In 3D there is never enough Time to do Things right,
but there's always enough Time to make them *look* right."
"psssst! i steal signatures... don't tell anyone! ;)"
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Size Of Arrays

Post by Little John »

PureNewbie wrote:I understand that PureBasic can use linked lists and collections instead of simple one dimensional arrays,
What are "collections"? Am I missing something?

Regards, Little John
PureNewbie
New User
New User
Posts: 2
Joined: Fri Aug 08, 2008 12:56 pm
Location: United Kingdom

Size Of Arrays

Post by PureNewbie »

Many thanks for the replies, I will give your suggestions a go.

My apologies to Little John - for "collections" read "structures" (too many languages going round and round .......).
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Size Of Arrays

Post by Little John »

PureNewbie wrote:My apologies to Little John - for "collections" read "structures"
Ah, I see. No problem.

Regards, Little John
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

@PureNewbie

a Structure is nothing in opposide to an Array.
you can put structured elements into an array as well as into a List.

the main difference is between Arrays and LLists:
an Array has fixed Dimensions (can be more than one) and fixed order for direct access.
a LList has dynamic size and dynamic order in only one dimension for sequential access.
oh... and have a nice day.
Post Reply