Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Invalid control array index Error

Status
Not open for further replies.

ogri

Programmer
Joined
Sep 26, 2000
Messages
74
Location
GB
Hi

I am getting an "Invalid control array index" error on some code. I am currently unable to recreate the error to check exactly where it is occuring. However I do now know which function it is being produced from.

According to the MSDN the error is caused by using a negative control array index. However I cannot see where this can be happening in this piece of code.

Are there any other causes of this error which I should look out for?

All the best

Keith
 
Further info, but not necessarily a solution:

Control arrays are created when you have more than one control of a specific type (label, textbox, combobox, etc.) which have the same name. This can be handy for a number of things that I won't go into here.

Anyway, you make references to a specific control in a control array by specifying its index number in parentheses after the shared control name. For example, if I had two combobox controls named Combo, they could be referred to as Combo(0) and Combo(1).

If you have code that uses a variable in place of the number, such as Combo(n), it will cause an error if the value of the variable results in a reference to a non-existing control (such as Combo(3) in my simple example).

The same thing could result from a calculation or a lookup type situation (such as Combo(UBound(MyArray,1)) or something like that).

Anyway, hopefully that gives you enough information to go on. Good luck!

BlackburnKL BlackburnKL
 
Hi

Thanks. I have actually managed to find the error, hidden in a sub routine. It uses a pair of combo boxes, and had a field saying which of the pair was true (used to check if the data had changed). Under unusual circumstances the field landed up with a value of -1, which resulted in the error when it was used checked if the combo box was still true

All the best

Keith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top