Sub Main()
-
Hi, I'm a C# type that just landed a VB.Net assignment and I'm having trouble getting a handle on Sub Main in VB.Net. The folks at the new place don't use Main while all the examples in documentation seem to. Evidently it's optional and not very VB6. Where does control get passed to if there isn't one? Also, every example that I've seen places Main() in a Module, not a Class. Is that important or does it just default it to Public? Thanks in advance.
-
Hi, I'm a C# type that just landed a VB.Net assignment and I'm having trouble getting a handle on Sub Main in VB.Net. The folks at the new place don't use Main while all the examples in documentation seem to. Evidently it's optional and not very VB6. Where does control get passed to if there isn't one? Also, every example that I've seen places Main() in a Module, not a Class. Is that important or does it just default it to Public? Thanks in advance.
You're right. The Main() function is optional in VB. You can set the app's "startup object" via Project Properties. 1) Go to the Solution Explorer. 2) Right click the project and select Properties. 3) Select CommonProperties\General in the tree. 4) Select the Startup Object and click OK. (Choose "Sub Main" if you want it to call your Main() function.) You can place the Main() anywhere you want. In a Module or in a Class. It must be defined as Public and Shared (ie: static), just like how you would do it in C#.
Public Class Main
Public Shared Sub Main(ByVal CmdArgs() As String)
End Sub
End Class