Click here to Skip to main content
15,878,852 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
We have a large vb6 program that has many forms.
We have the need to load then unload about 3 forms.

After unloaded 1 and only 1 particular form we get 340 Control array element doesn't exist on frmStoreControls.fraBase(0).Left but NOT on frmStoreControls.fraBase(1).Left

fraBase is a frame control array defined at design time frmStoreControls.txtOrderStatusCodesAs1(0).Left which is in fraBase(0) does NOT generate an error.

I do not understand what is happening.
Can anyone please explain and how can this be fixed?

Thanks
Posted
Updated 24-Mar-11 3:50am
v2

1 solution

I had the same issue with some textboxes in two of my programs. They would load just fine the first time that the form was loaded, but I kept on getting a "340 error" when I reloaded the form (after an unload command, of course) and when used the "textbox(xx).setfocus" method. After hours of searching, I found out that the error was generated only in specific forms in which I had declared an object variable (let's call it LastObject) that I use in order to reset the focus at the last used textbox, after clicking on a button.

Let's see the code:

Dim LastObject As Object

Private Sub Form_Activate()
Set LastObject = InpText(1)
 InpText(1).SetFocus
End Sub

This triggered the "340 Control array... error". So, after hours of searching (as I said before), I found that if I assigned the LastObject value after the form was loaded and activated, or after I was done with all the manipulations of the controls in the Form_Activate sub, I got no error. For instance, this:

Private Sub Form_Activate()
 InpText(1).SetFocus
 blah blah
 blah blah
Set LastObject = InpText(1)
End Sub

...or this:

Private Sub Form_Activate()
 InpText(1).SetFocus
 blah blah
 blah blah
 SetLastObject
End Sub

Private Sub SetLastObject()
Set LastObject = InpText(1)
End Sub

...both work just fine in my programs now.

I hope this was helpful.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900