Results 1 to 17 of 17

Thread: Weird Stuff...What is this?

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 1999
    Posts
    40

    Post

    '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
    ?????????????????????????

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,175

    Post

    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

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 1999
    Posts
    40

    Post

    NO NO NO..
    The loop says from 1 to 47...it should never reach 48...why is it going to 48
    ??????????????????????????????????????????

  4. #4

    Thread Starter
    Member
    Join Date
    Jul 1999
    Posts
    40

    Post

    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!

  5. #5
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    Post

    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.

  6. #6
    Junior Member
    Join Date
    Nov 1999
    Posts
    23

    Post

    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?


  7. #7

    Thread Starter
    Member
    Join Date
    Jul 1999
    Posts
    40

    Post

    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


  8. #8
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892

    Post

    Did you declare ICheck like this?

    Dim ICheck(1 To 47) As Whatever

    ------------------
    Yonatan
    Teenage Programmer
    E-Mail: RZvika@netvision.net.il
    ICQ: 19552879
    AIM: RYoni69

  9. #9

    Thread Starter
    Member
    Join Date
    Jul 1999
    Posts
    40

    Post

    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.

  10. #10
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,176

    Post

    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).]

  11. #11
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    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


  12. #12

    Thread Starter
    Member
    Join Date
    Jul 1999
    Posts
    40

    Post

    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.

  13. #13
    Junior Member
    Join Date
    Nov 1999
    Posts
    23

    Post

    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.

  14. #14

    Thread Starter
    Member
    Join Date
    Jul 1999
    Posts
    40

    Post

    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!

  15. #15
    Addicted Member
    Join Date
    Jan 1999
    Location
    Sydney,NSW,Australia
    Posts
    178

    Post

    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

  16. #16
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,175

    Post

    I did exactly what you are saying you are doing, which I think is this:
    Code:
    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

  17. #17
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105

    Post

    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).]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width