How do I define a Main method in a Class versus a Module?

If you are NEW to Classes

Classes is a different concept than a module module is a collection of functions , but class is a template which should be instantiating an object and use.

First go though the OOP basics in VB.NET here

If your are a Pro

Use Shared Sub Main() ...


My guess is that your application is a command line application. Make the class Public and Shared...

Public Shared Sub Main()

End Sub

For any future reader, if your Main() is in a Module (not Class Module) and you're still getting this error, make sure the method does not take any parameters. Unlike C++, VB.NET doesn't take command-line arguments as a Main method's parameters. Instead you should define a zero-parameter Main() method and use My.Application.CommandLineArgs to access the supplied parameters. I banged head for some time before I realized this.


Modules are just classes where all members are shared (static in C#).

If you want to change a module into a class, just add the Shared modifier to its members:

Shared Sub Main() ...

Although, I really think modules are a good idea and a perfect place to put your Main function.