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.

DarkBASIC Discussion / wierd error

Author
Message
ico2
21
Years of Service
User Offline
Joined: 3rd Jan 2004
Location:
Posted: 11th Jan 2004 21:07
when i run this code i get this error: runtime error at line nine. array accessed out of bounds.
Sjakie
21
Years of Service
User Offline
Joined: 17th Dec 2003
Location: Netherlands - Delft
Posted: 11th Jan 2004 22:16
this means youve created an array (like Whatever(100)) and you tried to access a value that doesn't exists like if Whatever(101)= ...

Juzt a dude who likez progging
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 11th Jan 2004 23:25
You have:



but your array doesn't go up to 100, only 25

"eureka" - Archimedes
Don Malone
22
Years of Service
User Offline
Joined: 27th Apr 2003
Location: Birmingham, Alabama
Posted: 12th Jan 2004 01:38 Edited at: 12th Jan 2004 01:40
Dont arrays start with 0 (zero) in all programming languages? Visual Basic has an option to start arrays at one but it must be declared at the start of the program.

If that is the case then the array would be (if the array has 100 elements) from 0 to 99.

I will double check this.

-----------------------------------

Well the manual indicates it starts at one so I must be mistaken. Sorry about that.

Wasting CPU Cycles since the 286 was a hot machine.
JoelJ
21
Years of Service
User Offline
Joined: 8th Sep 2003
Location: UTAH
Posted: 12th Jan 2004 02:17
thank you Dboy780, i have asked that before, and i dont know if i have ever gotten a straight answer...

ico2
21
Years of Service
User Offline
Joined: 3rd Jan 2004
Location:
Posted: 12th Jan 2004 07:45
thanks.
i changed it to "if spritenum=1 to 25" and it works
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 12th Jan 2004 08:42
Array's go from 0 to the number you declare it as, ie;
Dim array(100)
would have available array positions starting at 0, right through to 100.

Hope I Helped...

PS sorry for not helping ico2, I was just trying to clear things up for the others...


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
Don Malone
22
Years of Service
User Offline
Joined: 27th Apr 2003
Location: Birmingham, Alabama
Posted: 13th Jan 2004 04:38
I am repeating the Classic 1.13 manual (page 5 and 6)



and the For Next loop to read the data from page 6



I just thought I had heard several times on this forum that Arrays started with zero (0) and now I just don't know.

Test Time!!!!!!

Wasting CPU Cycles since the 286 was a hot machine.
Don Malone
22
Years of Service
User Offline
Joined: 27th Apr 2003
Location: Birmingham, Alabama
Posted: 13th Jan 2004 04:55
My test code (very sloppy I know) indicates that arrays do start at 1 in Classic.



Is there something wrong in this code or is this correct?

Wasting CPU Cycles since the 286 was a hot machine.
Travis
21
Years of Service
User Offline
Joined: 9th Nov 2003
Location: West Aust.
Posted: 13th Jan 2004 08:32
tj is right but just to clarify i bit if u said dim test(100) then you can use numbers 0 to and including 100 meaning you have 101 positions for data this can get confusing so i just make my arrays 0 - 100 but only ever use positons 1 to 100, thats my two cents
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 13th Jan 2004 10:03
try this:



There ya, it's like Travis said, you can use 0 up to the number you delcared it as , inclusive, ie, if you declare it as DIM array(10) you can use 0 to 10 inclusive.

Hope I Helped...


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
Don Malone
22
Years of Service
User Offline
Joined: 27th Apr 2003
Location: Birmingham, Alabama
Posted: 13th Jan 2004 13:51
So I am right and right. I just made the wrong test. I should have tested with the code as follows.



really testing the zero element instead of the one element.

Thanks for the insight Travis.

Wasting CPU Cycles since the 286 was a hot machine.
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 16th Jan 2004 05:32
DB actually creates 1 more element in the array than you specify. Since all languages start with zero, the parameter is the number of elements you want. In DB, the parameter is the highest element number, so you end up with 1 extra.

thing(100) is thing(0) through thing(99) of most languages, resulting in 100 elements. DB goes thing(0) to thing(100), making it 101 elements.

I think I've just be very redundant.

"eureka" - Archimedes
Don Malone
22
Years of Service
User Offline
Joined: 27th Apr 2003
Location: Birmingham, Alabama
Posted: 17th Jan 2004 14:48
But it is the clarification that most non-power users and learners (like me) need. Thanks for the added reply.

Wasting CPU Cycles since the 286 was a hot machine.

Login to post a reply

Server time is: 2025-05-22 16:59:17
Your offset time is: 2025-05-22 16:59:17