“未定义用户定义类型” Windows 7 下 VB 6 出现错误
我使用的是 Windows 7,我的项目是 VB 6.0。我在执行程序时遇到错误。它显示错误:
未定义用户定义类型。
这是我的代码:
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
我该如何解决这个错误?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当错误出现时,编译器会自动突出显示函数声明的第一行。这意味着错误发生在该行的某个位置。有时这并不像您希望的那么有帮助,但在这种情况下,它可以告诉您很多信息。
具体来说,出现在函数声明中的唯一“用户定义类型”(实际上是唯一的“类型”)是
MSComctlLib.Button
。编译器错误消息在这里告诉您的是,它不知道MSComctlLib.Button
是什么。因此,它假设它是“用户定义”类型,因为它通常不知道用户在谈论什么。 :-)无论哪种方式,修复都很简单:您需要告诉编译器 MSComctlLib.Button 是什么。在这种情况下,它猜测它是用户定义类型,这是错误的。它实际上是 Microsoft Windows 通用控件库中提供的按钮控件。 要告诉 VB 6 有关此控件的信息,您需要将相应的组件添加到您的项目中。请按照下列步骤操作:
从“项目”菜单中选择“组件”。
在出现的对话框中,将列表向下滚动大约 2/3 到 M。勾选“Microsoft Windows Common Controls 6.0”和“Microsoft Common Controls-2 6.0”项目。 (如果您的服务包有不同的名称,请不要担心。)
单击“确定”按钮。如果你动作够快,你会看到一些额外的控件被添加到你的工具箱中。这些是您刚刚添加的组件库提供的控件。这些控件中有一个名为
Button
。最后,尝试再次编译并运行您的项目 - 这次一切都应该没问题,因为现在编译器知道
MSComctlLib.Button
类型是什么。如果您仍然不这样做,它会在您的工具栏上显示一个按钮。工具栏控件由公共控件库提供,它包含定义该工具栏上出现的单个按钮的类型。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 aMSComctlLib.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.听起来您缺少对对象库的引用。
(你在其他地方执行没有错误吗?)
Sounds like you are missing a reference to an object library.
(Have you executed it without errors elsewhere?)
我认为您只是从其他地方复制并粘贴了该代码。通常,如果您想引用 MSComctlLib,通常会先执行 Cody Gray 此处所述的步骤,然后才能访问类型库。
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.