[.Net 2.0] Console Application - Module1.vb

  • Thread starter Thread starter Rob Meade
  • Start date Start date
R

Rob Meade

Hi all,

Ok - I have the ability to write my own little console application, but yet
I find myself asking a bit of a noddy question...

I program mainly web based applications, so I'm familiar with webforms.
Whilst I've written a console app a few times now, I've never really
understood what the purpose of a "module" was? Had a quick look on Google
but didn't seem to find anything that actually described what it "was"..

Is it effectively what a web form is for ASP.Net, what a WinForm is for
VB.Net...? Do I actually need it? Could I just have an opening class that
gets run from the start?

Any info would be appreciated... due to my lack of understanding seeing a
"module" amongst all my shiny classes makes me feel that my console
application is "dirty" in some way... and I have the urge to delete it! :o)

Thanks in advance for any help.

Regards

Rob
 
Hi Rob,

the Module1.vb is part of the template for the Console project. It contains
the Sub Main starting point for the application. I found a good explanation
of module in MSDN about the module statement:

"A Module statement defines a reference type available throughout its
namespace. A module (sometimes called a standard module)is similar to a
class but with some important distinctions. Every module has exactly one
instance and does not need to be created or assigned to a variable. Modules
do not support inheritance or implement interfaces. Notice that a module is
not a type in the sense that a class or structure is - you cannot declare a
programming element to have the data type of a module.

You can use Module only at namespace level. This means the declaration
context for a module must be a source file or namespace, and cannot be a
class, structure, module, interface, procedure, or block. You cannot nest a
module within another module, or within any type."

This is the documentation about startup object from MSDN:

"If Enable application framework is cleared, this list becomes Startup
object and shows both forms and classes or modules with a Sub Main. "

This means you can remove remove the module and in the project properties
set a class to be the startup object. I just tried it and my class looked
like this.

Public Class Class1
Public Shared Sub Main()
Console.WriteLine("It works!!!")
End Sub
End Class


Best regards,
Andreas Johansson
 
...
This means you can remove remove the module and in the project properties
set a class to be the startup object. I just tried it and my class looked
like this.

Public Class Class1
Public Shared Sub Main()
Console.WriteLine("It works!!!")
End Sub
End Class

Hi Andreas.

Many thanks for your reply, really appreciated...

And I think you have in part answered my next question... Since completing
the console app I was just writing, I wanted to use one of my generic
methods I have in a base class, but I was unable to inherit in the module
(as you mention), so if I follow what you have said, and change my start up
object to be a class instead, obviously the inheritence will work - but does
not using a module cause me any other problems?

Thanks agian for our help,

Regards

Rob
 
Back
Top