Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"User-defined type not defined" error in VB 6 under Windows 7

Tags:

windows-7

vb6

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?

like image 814
sunil.nishad87 Avatar asked Jan 13 '11 07:01

sunil.nishad87


1 Answers

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:

  1. From the "Project" menu, select "Components".

  2. 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.)

         Components dialog in VB 6 IDE

  3. 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.

like image 98
Cody Gray Avatar answered Oct 22 '22 12:10

Cody Gray