Results 1 to 7 of 7

Thread: [RESOLVED] Declare array in eVB

  1. #1

    Thread Starter
    Addicted Member yolandre's Avatar
    Join Date
    Oct 2004
    Posts
    177

    Resolved [RESOLVED] Declare array in eVB

    Can anyone confirm the correct way of declaring an array in eVB? I recently ported an app from VB6 to eVB.

    The following declaration appears in the VB6 app:
    Private MyCounter(0 To 30) As Long

    I replaced the above declaration with the following in eVB:
    Public MyCounter(30) As Long

    I also tried the following:
    Public MyCounter(30, 30) As Long

    Unfortunately I still get an error message in eVB: Subscript out of range: ‘MyCounter’.

    Any advice?
    Last edited by yolandre; Jan 1st, 2008 at 03:08 AM.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: Declare array in eVB

    One thing you can do is leave off that "As Long" part. Since every variable in eVB is a Variant, specifying the type does little more than suggest what you expect to put in there. You can assign the value "Blue" to that line, and Blue it will be.

    (I don't much like eVB, especially for this reason).

    Since I don't like eVB, I haven't worked with it much, and when I did was several years ago. You might try declaring the array with no size, then use ReDim to size it. My thinking is that since all variables are Variants, it might be that you create a variable for the array, and then have to dimension it as the next step.

    Just a guess, though.
    My usual boring signature: Nothing

  3. #3
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: Declare array in eVB

    When do you get the error - at declaration or in use?

    There is no problem with the declaration - are you sure you are not exceeding the bounds of the array?

    Pete

  4. #4

    Thread Starter
    Addicted Member yolandre's Avatar
    Join Date
    Oct 2004
    Posts
    177

    Re: Declare array in eVB

    The app compiles with no errors, i.e. error occurs during runtime.

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Declare array in eVB

    MyCounter(0,30) ?

  6. #6

    Thread Starter
    Addicted Member yolandre's Avatar
    Join Date
    Oct 2004
    Posts
    177

    Re: Declare array in eVB

    Been there, done that. It still generates an error...

  7. #7
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: Declare array in eVB

    Hi,
    if it is a run time error, you are probably addressing outside the array, trying to access element 31.

    Put an 'If index >= 30 then' around your array access and see if the error goes away.

    Pete

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