|
-
May 19th, 2013, 10:37 AM
#1
Thread Starter
New Member
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
-
May 19th, 2013, 11:16 AM
#2
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)
-
May 19th, 2013, 11:26 AM
#3
Thread Starter
New Member
Re: Having trouble with control array
right when the timer starts
-
May 19th, 2013, 11:57 AM
#4
Re: Having trouble with control array
 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.
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)
-
May 19th, 2013, 01:05 PM
#5
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
-
May 19th, 2013, 01:08 PM
#6
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.
-
May 19th, 2013, 01:18 PM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|