Run-time error 340 - Control array element '4' doesn't exist 
Author Message
 Run-time error 340 - Control array element '4' doesn't exist

I'm using VB6 (SP3) .

I used bound control array on my form. At time, I got the error "Control
array element "4" doesn't exist although element 4 is on the form. I checked
all the array elements, they are all in sequence and I did'nt miss any
element.

Sometime this error comes on Element "5" sometime on "6" and most of the
time, it didn't show the error.
I don't know what's going on. Should I don't use control array on my form. I
compiled my application in P-Code as well as in Native Code, result is same.

Thanks in advance.



Thu, 24 Jan 2002 03:00:00 GMT  
 Run-time error 340 - Control array element '4' doesn't exist

Quote:

>I'm using VB6 (SP3) .

>I used bound control array on my form. At time, I got the error "Control
>array element "4" doesn't exist although element 4 is on the form. I
checked
>all the array elements, they are all in sequence and I did'nt miss any
>element.

How did you check it (it's possible you made an error)?

Quote:
>Sometime this error comes on Element "5" sometime on "6" and most of the
>time, it didn't show the error.

Are you loading and unloading elements at run time?

Quote:
>I don't know what's going on. Should I don't use control array on my form.

This would only be reasonable if there were a problem with control
arrays. There isn't, and control arrays are necessary to reduce resource
use in VB. The reasonable assumption is that there is something
wrong in the forms and code you have written.

Just a reminder, control arrays are zero indexed, and never contain
gaps in the sequence. If you unload element 3, for example, element
4 immediately becomes element 3, even within a loop. When
removing elements from a control array, therefore, start at the
last element and work to the front.

If this doesn't help, post some code.



Thu, 24 Jan 2002 03:00:00 GMT  
 Run-time error 340 - Control array element '4' doesn't exist

<cut>

Quote:
> Just a reminder, control arrays are zero indexed, and never contain
> gaps in the sequence. If you unload element 3, for example, element
> 4 immediately becomes element 3, even within a loop. When
> removing elements from a control array, therefore, start at the
> last element and work to the front.

That is not true -- control arrays do not collapse to fill in gaps.    If
you unload element 3 then element 4 stays right where it was.


Thu, 24 Jan 2002 03:00:00 GMT  
 Run-time error 340 - Control array element '4' doesn't exist
Hi Ron:

Quote:
>Just a reminder, control arrays are zero indexed, and never contain
>gaps in the sequence. If you unload element 3, for example, element
>4 immediately becomes element 3, even within a loop. When
>removing elements from a control array, therefore, start at the
>last element and work to the front.

This statement is true for collections, but not control arrays.  You can
load/unload control array indexes out of sequence:

   Private Sub Form_Load()
      Dim TBox As TextBox

      'Note:  Text1(0) is placed on the form at design time
      Load Text1(2)
      Load Text1(4)
      Load Text1(6)

      For Each TBox In Text1
         Debug.Print TBox.Index
      Next TBox

      Unload Text1(4)
      For Each TBox In Text1
         Debug.Print TBox.Index
      Next TBox
   End Sub

Doug.



Thu, 24 Jan 2002 03:00:00 GMT  
 Run-time error 340 - Control array element '4' doesn't exist

Quote:

>Hi Ron:

>This statement is true for collections, but not control arrays.  You can
>load/unload control array indexes out of sequence:

True. I have Got to stop responding to posts before I
have my first cup of coffee. Thanks to you and Bob Butler.


Thu, 24 Jan 2002 03:00:00 GMT  
 Run-time error 340 - Control array element '4' doesn't exist
Hi Ron:

Quote:
>I have Got to stop responding to posts before I
>have my first cup of coffee.

Same here :)

Doug.



Thu, 24 Jan 2002 03:00:00 GMT  
 Run-time error 340 - Control array element '4' doesn't exist
Thanks for your response

I have checked my code and I found that control array starts from 1 not from
0.

Could it be the reason for error ?


Quote:


> >I'm using VB6 (SP3) .

> >I used bound control array on my form. At time, I got the error "Control
> >array element "4" doesn't exist although element 4 is on the form. I
> checked
> >all the array elements, they are all in sequence and I did'nt miss any
> >element.

> How did you check it (it's possible you made an error)?

> >Sometime this error comes on Element "5" sometime on "6" and most of the
> >time, it didn't show the error.

> Are you loading and unloading elements at run time?

> >I don't know what's going on. Should I don't use control array on my
form.

> This would only be reasonable if there were a problem with control
> arrays. There isn't, and control arrays are necessary to reduce resource
> use in VB. The reasonable assumption is that there is something
> wrong in the forms and code you have written.

> Just a reminder, control arrays are zero indexed, and never contain
> gaps in the sequence. If you unload element 3, for example, element
> 4 immediately becomes element 3, even within a loop. When
> removing elements from a control array, therefore, start at the
> last element and work to the front.

> If this doesn't help, post some code.



Fri, 25 Jan 2002 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. run-time error '340' Control array element '8' doesn't exist

2. Run time error 340 - control array element does not exist

3. Control Array Element '0' Doesn't Exist (Error 340)

4. Control array element doesn't exist error

5. Error 340: Control array element doesn't exist! Why?

6. Error 340: Control array element doesn't exist! Why?

7. Run-time error '462': The remote server machine does not exist or is unavailable

8. Error 340: Control array item (0) doesn't exist?!?! Eh?!?

9. Run time error '35605': This item's control has been deleted

10. Table's Field doesn't bind to HTML Control Element

11. Table's Field doesn't bind to HTML Control Element

12. Table's Field doesn't bind to HTML Control Element

 

 
Powered by phpBB® Forum Software