Reputation: 109
I created a new VB project(console application) in Visual Studio 2010 and added a new class(vb class) to the project.
Can the new class I added be used as a startup object in the project properties?
If yes, how? I can't see the new class I created in the startup object dropdown in project properties.
Is there any other way of setting up the class as startup object in the project properties startup object dropdown menu?
Upvotes: 3
Views: 4025
Reputation: 27322
Yes you can do this but you will have to move your Sub Main
into the class and declare it as Shared:
Shared Sub Main()
Console.WriteLine("Startup")
End Sub
Then change the Startup Object to Sub Main
Upvotes: 2
Reputation: 7830
Yes, it is possible - you need to make your Main
method in your class static, using the shared
keyword:
Public Class AppStarter
Shared Sub Main()
Console.WriteLine("Entry point")
End Sub
End Class
This class will be visible in the project settings:
Another option would be to create a static module where your Main
is placed and in this main function(sub) to use your custom class.
More information about how to do this (for console and GUI application), can be found in this MSDN How to: Change the Startup object for an application (Visual Basic).
Upvotes: 1
Reputation: 20100
using this show the Class1
in the dropdown
you can then select Class1
as the startup
Public Class Class1
Public Shared Sub Main()
Console.WriteLine("Hello world!")
Console.ReadKey()
End Sub
End Class
Upvotes: 0