I am using Windows 7 and my project is in VB 6.0. I am getting errors while I am executing my program. It shows the error:
User-defined type not defined.
Here is my code:
Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
Select Case Button.Key
Case "trace": Call mntrace_Click
Case "snrplot": Call mnSnrplot_Click
Case "skyplot": Call mnskyplot_Click
Case "nmea": Call mnNmea_Click
Case "navigation": Call mnNavigation_Click
Case "survey": Call mnSurvey_Click
Case "pause/start": Call mnpause_Click
Case "save": Call mnsave_Click
Case "print": Call mnprint_Click
Case "offline": Call mnoffline_Click
End Select
End Sub
How can I solve this error?
The compiler is automatically highlighting the first line of the function declaration for you when the error appears. That means the error occurs somewhere within that line. Sometimes that's not as helpful as you'd like, but in this case, it manages to tell you quite a lot.
Specifically, the only "user-defined type" (really, the only "type" at all) that appears in the function declaration is MSComctlLib.Button
. What the compiler error message is telling you here is that it doesn't know what a MSComctlLib.Button
is. It therefore assumes it's a "user-defined" type because it often doesn't know what the user is talking about. :-)
Either way, the fix is simple: you need to tell the compiler what an MSComctlLib.Button
is. In this case, it guessed wrong in assuming that it is a user-defined type. It's actually a button control provided in the Microsoft Windows Common Controls Library. To tell VB 6 about this control, you need to add the corresponding component to your project. Follow these steps:
From the "Project" menu, select "Components".
In the dialog box that appears, scroll about 2/3 of the way down the list to the M's. Place a check by both the "Microsoft Windows Common Controls 6.0" and "Microsoft Common Controls-2 6.0" items. (Don't worry if yours have a different service pack designation.)
Click the OK button. If you're quick, you'll see some additional controls being added to your toolbox. These are the controls provided by the component libraries that you just added. Among those controls is one called Button
.
Finally, try to compile and run your project again—everything should be fine this time, because now the compiler knows what the MSComctlLib.Button
type is. In case you still don't, it's a button that appears on your toolbar. The toolbar control is provided by the Common Controls library, and it includes a type that defines an individual button appearing on that toolbar.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With