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
Re: Having trouble with control array
Can you tell us where the error occurs?
Re: Having trouble with control array
right when the timer starts
Re: Having trouble with control array
Quote:
Originally Posted by
mslvr40
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.
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.
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.
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!