[gameprogrammer] Re: subscript out of range?

  • From: Daniel Greeson <thecrow815@xxxxxxxxx>
  • To: gameprogrammer@xxxxxxxxxxxxx
  • Date: Mon, 31 Jan 2005 08:09:21 -0800 (PST)

I am programming in VB I can check my declarations that might be the problem 
because I did add the new declaration along with the new procedure, but if you 
could think of any more information it is still greatly appreciated.
Bob Pendleton <bob@xxxxxxxxxxxxx> wrote:On Mon, 2005-01-31 at 05:56 -0800, 
Daniel Greeson wrote:
> Hey everyone I hope everyone is doing well.
> 
> I am having a problem I keep getting a subscript out of range error. I just 
> added a graphics portion to my source code and this error is popping up I was 
> wondering if anyone could give me some information about this error. thanks 
> in advance,
> 
> ~Draven~
> 

Which language are you using? We need to know that to give you specific
information. In general it means that your program is trying to access a
part of a vector or array that does not exist. For example, in C you
might have the declaration:

int iv[10];

Which gives you a vector of 10 integers. The valid subscripts for that
vector are from 0 to 9 inclusive. If I had an expression that included
iv[10] or iv[-1] I would have an out of range subscript error. Now, you
most likely aren't using C because C doesn't normally check for
subscript errors. But, you get the idea.

The most common reason for getting a subscript error is a loop that goes
past the end of a vector. For example:

int i;
int iv[10];

for (i = 0; i <= 10; i++) {
printf("iv[%d] = %d\n", i, iv[i]);
}

Note that the test "i <= 10" will set to to values in the range 0 to 10
and 10 is an invalid subscript of the vector iv.

The error is most likely in your code. But, if you are passing out of
range values to a library function you could be triggering the error in
a library.

Bob Pendleton


> ---------------------------------
> Do you Yahoo!?
> Yahoo! Search presents - Jib Jab's 'Second Term'
> 
> 
> 
> ---------------------
> To unsubscribe go to http://gameprogrammer.com/mailinglist.html
> 
> 
> 



---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html




                
---------------------------------
Do you Yahoo!?
 Yahoo! Search presents - Jib Jab's 'Second Term'



---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html


Other related posts: