在 VB.NET 中声明属性
在我的 VB 6.0 代码中,我声明了以下行:
Attribute VB_Name = "MyFile"
但是,在 VB.NET 中,我收到错误“期望声明”。这不是声明吗?是否有一个很好的参考来查找 VB.NET 和 VB 6.0 之间的差异?
In my VB 6.0 code, I declare have the following line:
Attribute VB_Name = "MyFile"
However, in VB.NET, I get the error "expecting declaration". Isn't this a declaration statement? Is there a good reference for finding the differences between VB.NET and VB 6.0?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 VB.NET 中根本不需要上述代码。
在 VB 6 中,它在代码中指定文件的名称 - 这用于诸如窗口标题之类的内容,以及允许您可以在代码中显式限定对该类成员的引用。
在 VB.NET 中,类声明中使用的名称已经达到了该目的。您不再需要提供带有
属性
的显式名称。考虑以下迷你类:要从代码中的其他位置调用您命名为
MyFile
的类的DoWork
方法,您只需编写:在以前版本的 VB 中指定
VB_Name
属性后。另请注意,类/模块保存的文件名可能完全不同;您在类声明中指定的名称不依赖于您为文件本身指定的名称,就像以前的版本一样。
There's no need for the above code at all in VB.NET.
In VB 6, it specifies the name of the file from within code—this is used for things like the window title, as well as allowing you to explicitly qualify references to the members of that class in your code.
In VB.NET, the name used in the declaration of the class already serves that purpose. You no longer need to provide an explicit name with an
Attribute
. Consider the following mini-class:To call the
DoWork
method of the class you've namedMyFile
from another place in your code, you would simply write:just as you could after you specified the
VB_Name
attribute under previous versions of VB.Also note that the file name that your class/module is saved as can be something completely different; the name you specify in the class declaration is not dependent on the name you've given the file itself, just like previous versions.