Array index out of bounds?

Blitz3D Forums/Blitz3D Beginners Area/Array index out of bounds?

Q(Posted 2005) [#1]
I keep this strange 'Array index out of bounds' error when I assign 2 values to an array. This error ony shows up for certain values. What's the deal?!


WolRon(Posted 2005) [#2]
You are referencing the array beyond the bound you set for it.

With Debug ON, you will be told this regardless, but with Debug OFF, you may/may not be notified, and the program may just unexpectedly crash.

So, the moral of the story is to use Debug unless you are creating a release version of your program.


big10p(Posted 2005) [#3]
[edit] Arg! Not again?! Wolron, you keep doing this to me - do it again and I'll be forced to slap your legs! :P

The 'Array index out of bounds' error only shows up in debug mode, I believe. You simply must be using an array index that's out of range.


jhocking(Posted 2005) [#4]
The 'Array index out of bounds' error only shows up in debug mode, I believe. You simply must be using an array index that's out of range.

An explanation worthy of Microsoft. Way to just restate the error message.

@valorden: code please


big10p(Posted 2005) [#5]
An explanation worthy of Microsoft. Way to just restate the error message.
Well, the error message is hardly ambiguous. Besides, it doesn't say "You only see this error when in debug mode".


Shifty Geezer(Posted 2005) [#6]
Dim my_array(10)

my_array(1)=5
my_array(6)=8
my_array(10)=9
my_array(11)=7 <---- This line cause Array Index Out of Bounds error. Array goes from 0 to 10, and you're trying to address index number 11.


jhocking(Posted 2005) [#7]
We don't think it's ambigious, but clearly valorden needs further elaboration. Like I said, an explanation worthy of Microsoft; their tech writers routinely just restate the error message because, hey, it makes sense to them.


big10p(Posted 2005) [#8]
OK, I see what you mean now, jh. Maybe I should apply for a job at MS, then. :/


jhocking(Posted 2005) [#9]
@shifty geezer: Actually, wouldn't it go out of bounds on my_array(10)? I thought array indecies go from 0 to n-1, if you dim the array with n spaces.


Q(Posted 2005) [#10]

Dim my_array(10)

my_array(1)=5
my_array(6)=8
my_array(10)=9
my_array(11)=7 <---- This line cause Array Index Out of Bounds error. Array goes from 0 to 10, and you're trying to address index number 11.




Ahh, that's exactly what was wrong! Thanks.


Sledge(Posted 2005) [#11]

I thought array indecies go from 0 to n-1



In most (of the) languages (I've come across) you dimension an array referencing the number of slots; in Blitz you reference the last slot. It's sick and twisted, but that's the way it is :D


jhocking(Posted 2005) [#12]
Ah whatever; arrays ain't my bag anyway.