开发者

Declare Attribute in VB.NET

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 betwee开发者_如何学Pythonn VB.NET and VB 6.0?


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:

Public Class MyFile
    Public Sub DoWork()
        'do something here
    End Sub
End Class

To call the DoWork method of the class you've named MyFile from another place in your code, you would simply write:

MyFile.DoWork()

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜