Click to See Complete Forum and Search --> : Weird Stuff...What is this?
Juillet
Dec 7th, 1999, 09:27 PM
'load the check variables into arrays
Dim a As Integer
For a = 1 To 47
ICheck7(a) = a
Next a
gives me subscript out of range.
when I debug..a = 48
how can that happen when I explicitly tell
it from 1 to 47
?????????????????????????
MartinLiss
Dec 7th, 1999, 09:53 PM
It happens because you don't have a 48th entry in the array. (You don't have a zeroith entry either). If you Dim an array with ICheck7(47) you will have a 48th entry which would be referenced as ICheck(47), because the first entry in the array is ICheck(0). In your case you have only 47 entries and the first one is ICheck(1).
------------------
Marty
Juillet
Dec 7th, 1999, 09:57 PM
NO NO NO..
The loop says from 1 to 47...it should never reach 48...why is it going to 48
??????????????????????????????????????????
Juillet
Dec 7th, 1999, 10:01 PM
I have shhhhhh..for brains..of course it goes to 48..the for is a top check not a bottom check loop...
Oh Man...dumb dumb dumb!
netSurfer
Dec 7th, 1999, 10:03 PM
Wen do you debug the value of a? If you do it after the loop runs it will be 48. How do you declate lcheck7? This is Marting meant, I think. If you declare it as lcheck7(47) then it's values are actually lcheck7(0) to lcheck7(46), it counts (0) as the first one.
MR
Dec 7th, 1999, 10:05 PM
When you execute a for next loop it will increment the number first and then check to see if it should continue.
For a = 1 To 47
ICheck7(a) = a
Next a
a will turn 48 and then check to see if it >= to 1 or <=47
What line of code are you getting the error on?
Juillet
Dec 7th, 1999, 10:29 PM
yea...1 to 47 should stop at 47
inside the loop the icheck(a) should stop at 47 even though a actually goes to 48
but for some reason my array won't load..subscript out of range and it shouldn't happen because a = 1 to 47
and so my array should be 47 numbers, 1 to 47
Yonatan
Dec 7th, 1999, 10:32 PM
Did you declare ICheck like this?
Dim ICheck(1 To 47) As Whatever
------------------
Yonatan
Teenage Programmer
E-Mail: RZvika@netvision.net.il
ICQ: 19552879 (http://www.icq.com/19552879)
AIM: RYoni69
Juillet
Dec 7th, 1999, 10:41 PM
Actually I declared it as variant but other than wasted space it should matter
Dim iCheck7(1 to 47)
It doesn't seem to hinder the effor..as when I list the array outside the loop it has 47 numbers in it..1 to 47...why inside the loop does it go out of bounds when if a = 48 it should not enter the for loop.
Aaron Young
Dec 8th, 1999, 12:01 AM
Are you using the value of a outside the For Loop? If so, at that point it would be 48 and using on the Array would generate the Subscript out of Range Error.
------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net
[This message has been edited by Aaron Young (edited 12-08-1999).]
Serge
Dec 8th, 1999, 12:11 AM
Aaron is right, your counter variable would be 1 (one) more after the loop then the maximum in the loop. So, this error would accur only if you use this variable as an index after the loop, or if your array has less elements.
------------------
Serge
Software Developer
Serge_Dymkov@vertexinc.com
Access8484@aol.com
ICQ#: 51055819 (http://www.icq.com/51055819)
Juillet
Dec 8th, 1999, 01:45 AM
Ok..thanks all..sorry abut the late reply...Xmas Lunch..
like I said it doesn't do anything ,error wise, outside the loop but if put a toggle on and debug it, inside the loop it claims to be out of bounds looking for 48 and I didn't think it should ever reach 48 inside the loop because once it's 48 on the bottom it should stop at that point...so inside the loop iCheck7(a) should never pass 47.
outside the loop the array holds the 47 numbers 1 to 47...
it's no biggie but it sure surprised me as to how it could increment to 48 inside the loop.
MR
Dec 8th, 1999, 02:21 AM
even if you set a = 1 to 47 if the arrays option base 0 which is the default your array will start with 0. if you want your array to start with 1 you must declare it with the option base 1 statement.
Juillet
Dec 8th, 1999, 02:51 AM
true..the array is declared
dim iCheck7(1 to 47)
so it is not 0 based
only if I dim it
Dim iCheck7(46)
then I have a 47 number array 0 based
but because I can't have any 0's I used the 1 to 47 method.
I'v reposted another above this one as it's getting too long and I'm still lost
...I give up!
jritchie
Dec 8th, 1999, 07:28 AM
This is typically computer problem.
If you declare an array
Private Array(47) as Integer
In effect you are using memory variables of
Array(0)....Array(47)
If you then loop
For a = 1 to 47
You are by-passing the first array element Array(0)and going beyond the Array boundary by 1. When a = 47 you are accessing Array(48)
therefore a boundary error.
As some one mentioned declared your array
Private Array(1 to 47) as Integer
Therefore memory is set aside for
Array(1).....Array(47)
and you can
For a = 1 to 47
without getting an error
MartinLiss
Dec 8th, 1999, 11:03 AM
I did exactly what you are saying you are doing, which I think is this:Dim iCheck7(1 To 47)
Dim a As Integer
For a = 1 To 47
iCheck7(a) = a
Next a
It works just fine. Are you getting a run-time error, or are you just saying that you get an error when you go to the Immediate window and type ?iCheck(48). Also BTW, variants are not only wasteful of space, they are slow.
------------------
Marty
JHausmann
Dec 8th, 1999, 11:31 AM
Out of curiousity, what's "a" defined as?
Never mind, Marty pointed it out...
[This message has been edited by JHausmann (edited 12-08-1999).]
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.