在windows7下的VB 6中“用户定义类型未定义”错误。

时间:2022-11-06 18:58:27

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:

我使用的是Windows 7,我的项目是在VB 6.0中。我在执行程序时出错。它显示了错误:

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?

我怎样才能解决这个错误呢?

3 个解决方案

#1


20  

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

具体来说,在函数声明中出现的唯一“用户定义类型”(实际上,唯一的“类型”)是MSComctlLib.Button。编译器错误信息告诉你的是它不知道什么是MSComctlLib。按钮。因此,它假定它是一个“用户定义”类型,因为它通常不知道用户在谈论什么。:-)

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:

无论哪种方式,解决方法都很简单:您需要告诉编译器什么是MSComctlLib。按钮。在这种情况下,假设它是用户定义的类型,它猜错了。它实际上是微软Windows公共控件库中提供的按钮控件。要告诉VB 6这个控件,您需要将相应的组件添加到项目中。遵循以下步骤:

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

    在出现的对话框中,将列表的2/3向下滚动到M的列表中。在“Microsoft Windows Common Controls 6.0”和“Microsoft Common Controls-2 6.0”项下进行检查。(如果你的服务包名称不同,不要担心。)

         在windows7下的VB 6中“用户定义类型未定义”错误。

         

  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.

    单击OK按钮。如果您很快,您将看到一些额外的控件添加到您的工具箱中。这些是您刚刚添加的组件库提供的控件。在这些控件中有一个叫做按钮。

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.

最后,尝试编译并运行您的项目——这一次一切都应该很好,因为现在编译器知道MSComctlLib是什么。按钮类型。如果你仍然不知道,它是一个出现在你的工具栏上的按钮。工具栏控件是由公共控件库提供的,它包括一个定义在工具栏上出现的单个按钮的类型。

#2


0  

Sounds like you are missing a reference to an object library.

听起来好像你错过了一个对象库的引用。

(Have you executed it without errors elsewhere?)

(你在其他地方没有错误地执行过吗?)

#3


0  

I think you just copied and pasted that code from elsewhere. Normally, if you wanted to reference MSComctlLib, you will normally do first the steps stated by Cody Gray here before you can access the Type Library.

我认为你只是复制粘贴了其他地方的代码。通常,如果您想引用MSComctlLib,您通常会首先在访问类型库之前先完成Cody Gray所述的步骤。

#1


20  

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

具体来说,在函数声明中出现的唯一“用户定义类型”(实际上,唯一的“类型”)是MSComctlLib.Button。编译器错误信息告诉你的是它不知道什么是MSComctlLib。按钮。因此,它假定它是一个“用户定义”类型,因为它通常不知道用户在谈论什么。:-)

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:

无论哪种方式,解决方法都很简单:您需要告诉编译器什么是MSComctlLib。按钮。在这种情况下,假设它是用户定义的类型,它猜错了。它实际上是微软Windows公共控件库中提供的按钮控件。要告诉VB 6这个控件,您需要将相应的组件添加到项目中。遵循以下步骤:

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

    在出现的对话框中,将列表的2/3向下滚动到M的列表中。在“Microsoft Windows Common Controls 6.0”和“Microsoft Common Controls-2 6.0”项下进行检查。(如果你的服务包名称不同,不要担心。)

         在windows7下的VB 6中“用户定义类型未定义”错误。

         

  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.

    单击OK按钮。如果您很快,您将看到一些额外的控件添加到您的工具箱中。这些是您刚刚添加的组件库提供的控件。在这些控件中有一个叫做按钮。

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.

最后,尝试编译并运行您的项目——这一次一切都应该很好,因为现在编译器知道MSComctlLib是什么。按钮类型。如果你仍然不知道,它是一个出现在你的工具栏上的按钮。工具栏控件是由公共控件库提供的,它包括一个定义在工具栏上出现的单个按钮的类型。

#2


0  

Sounds like you are missing a reference to an object library.

听起来好像你错过了一个对象库的引用。

(Have you executed it without errors elsewhere?)

(你在其他地方没有错误地执行过吗?)

#3


0  

I think you just copied and pasted that code from elsewhere. Normally, if you wanted to reference MSComctlLib, you will normally do first the steps stated by Cody Gray here before you can access the Type Library.

我认为你只是复制粘贴了其他地方的代码。通常,如果您想引用MSComctlLib,您通常会首先在访问类型库之前先完成Cody Gray所述的步骤。