Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Author
Message
The Game Programmer
19
Years of Service
User Offline
Joined: 4th Dec 2004
Location: Sitting, and waiting, and staring, and..
Posted: 6th Feb 2005 11:47
Ok, I'm confused, first of all, what is an array, second, what is it good for, third what commands go with it, fourth, how do I use it? Too many questions? (I hope not)

Well, I'm trying aren't I.....

When Life gives you lemons make orange juice. Then sit back and wonder how it was done.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 6th Feb 2005 17:20
dim array(5)

The "5" means the number of elements in the array. "Dim" is used to create the memory needed for the array. "array", obviously, is the name of the array. It lets you greatly shorten the length of code.

This:
array_A = 456
array_B = 40
array_C = 545
array_D = 564

Does the same as this array:
array(1) = 456
array(2) = 40
array(3) = 545
array(4) = 564


Now say you wanted to add those number together.



No problem, but what if you had over 100 variables?



So how much easier that is?

"eureka" - Archimedes
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 6th Feb 2005 23:52
dont forget, the first element of an array is 0 (zero). So dimming...
Dim a(5)

gives you 6 elements, 0 thru 5

Clueless
20
Years of Service
User Offline
Joined: 16th Feb 2004
Location: Corbin, KY, USA
Posted: 8th Feb 2005 09:52
Quote: "
dont forget, the first element of an array is 0 (zero). So dimming...
Dim a(5)
"


and, confessing to a problem that once kept me up late many nights in a row cussing at my computer , unless an update has changed this, there's no bounds checking in DBP, so if you try to assign values to a(6) or a(100), you'll get away with it, but you're overwriting memory allocated to God-knows-what-else.

If you're lucky, the program will crash at the spot where you did the assignment. If you're unlucky (like me), you'll be changing other variables without knowing it.

Anyway, if you dim SomeArray(100), make sure you don't try to stick stuff into SomeArray(101).
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 8th Feb 2005 11:27
use array count() to return upperbound element

Login to post a reply

Server time is: 2024-09-23 11:34:55
Your offset time is: 2024-09-23 11:34:55