Results 1 to 7 of 7

Thread: Having trouble with control array

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2012
    Posts
    15

    Having trouble with control array

    sorry if this is a noob problem.

    I have 30 pictures in a control array and i keep getting an error message that says control array element 31 does not exist

    Private Sub tmrbarrel_Timer()
    For i = 0 To Image3.UBound
    If Image3(i).Visible = True Then
    Image3(i).Left = Image3(i).Left + 25
    End If
    Next
    End Sub

    Private Sub tmrcounter_Timer()
    i = i + 1
    Image3(i).Visible = True
    End Sub

  2. #2
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: Having trouble with control array

    Can you tell us where the error occurs?
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2012
    Posts
    15

    Re: Having trouble with control array

    right when the timer starts

  4. #4
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: Having trouble with control array

    Quote Originally Posted by mslvr40 View Post
    right when the timer starts
    If I'm not mistaken, the code you posted has two Timer event subroutines. Can you be more specific? Can you provide as much detail about your problem as you can? Like, exactly where does the error happens? It becomes harder to pinpoint your issue when you don't tell us everything we should know about the problem.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  5. #5
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,272

    Re: Having trouble with control array

    Image3.UBound will return the highest .Index property assigned to your control array and not the number of elements in the control array (just tested)

    Therefore you have an Image3 control whose Index property is 31. Find it. Change it.
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  6. #6
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: Having trouble with control array

    I'm not sure what you are trying to do but here is what is going on.

    You must have i declared in the general declarations section of your form. In tmrbarrel_Timer you are looping from 0 to Image3.UBound (0 to 29). After 29 in the loop, i is incremented by 1 (now 30) and when it returns to the top of the loop and fails the check then it drops out of the loop. Meanwhile, tmrcounter_Timer adds 1 to i which makes it 31. It then tries setting the visibility of Image3(31) to true. Since you control array only goes to 29 you will get this error.

  7. #7
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,272

    Re: Having trouble with control array

    @MarkT - good point. I assumed that the error was occurring in the first timer sub and not the second one. Didn't even take much notice of the second one, actually!
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

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