“未定义用户定义的类型"Windows 7 下 VB 6 中的错误 [英] "User-defined type not defined" error in VB 6 under Windows 7

查看:31
本文介绍了“未定义用户定义的类型"Windows 7 下 VB 6 中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Windows 7,我的项目是 VB 6.0.我在执行程序时遇到错误.它显示错误:

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.

这是我的代码:

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.

具体来说,唯一的用户定义类型"(实际上,出现在函数声明中的唯一类型")是 MSComctlLib.Button.编译器错误消息在这里告诉您的是它不知道 MSComctlLib.Button 是什么.因此,它假定它是用户定义的" 类型,因为它通常不知道用户在说什么.:-)

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 是什么.在这种情况下,它假设它是用户定义的类型是错误的.它实际上是 Microsoft Windows 通用控件库中提供的一个按钮控件.要将这个控件告诉 VB 6,您需要将相应的组件添加到您的项目中.请按照以下步骤操作:

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. 来自项目"菜单,选择组件".

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

在出现的对话框中,将列表向下滚动大约 2/3 到 M.通过Microsoft Windows Common Controls 6.0"和Microsoft Windows Common Controls 6.0"进行检查.和Microsoft Common Controls-2 6.0"项目.(如果您的服务包名称不同,请不要担心.)

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

单击确定"按钮.如果速度快,您会看到一些额外的控件被添加到您的工具箱中.这些是您刚刚添加的组件库提供的控件.在这些控件中,有一个叫做 Button.

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.

最后,再次尝试编译并运行您的项目——这次一切都应该没问题,因为现在编译器知道 MSComctlLib.Button 类型是什么.如果您仍然没有,它是一个出现在您的工具栏上的按钮.工具栏控件由 Common Controls 库提供,它包含一种类型,用于定义出现在该工具栏上的单个按钮.

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.

这篇关于“未定义用户定义的类型"Windows 7 下 VB 6 中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆