- Visual Basic 6.0
After copying a control placed on a form in the VB 6.0 IDE you receive the following error message when you attempt to run the program.
The program will not compile correctly even after the VB control that you copied has been deleted from the form.
This seems to be a bug in the VB 6.0 IDE. Remember this?
It asked you if you wanted to place the control into an array so that multiple controls named ‘Command1’ in this case could be referenced from a common name i.e. Command1(0), Command1(1), Command1(2) etc.
Very occasionally the VB IDE gets this wrong, attempting to reference a control variable as an array variable. This in turn leads to non-compliable code and no clear way to get out of the problem.
The fix is to prevent the VB IDE from trying to treat the original variable as an array by removing its index parameter.
- Delete or rename the duplicate named control
- Note the name of the control in the error message
- Save your project and exit VB
- Open the location of your .vpb (Visual Basic Project) file
- Locate the .frm file (form) that your control appears in amongst the list of files
- Open notepad and drag and drop the .frm file into its window so that you can see the underlying code-behind the form
- Search the file for the name of the control named in the error message
- Beneath it you should find a parameter list associated with the control. Locate and delete the line “Index” line as highlighted below
- Save and exit notepad and restart the IDE
Or, if the control exposes it, clear the value of ‘index’ on the properties explorer in the IDE.