1. Technology

Modules, Structures, and Classes

Application Organization 101 - The Basics


Businesswoman typing on computer keyboard
Siri Stafford/Digital Vision/Getty Images
Updated July 01, 2014

There are just three ways to organize a VB.NET application.

  • Modules
  • Structures
  • Classes

But most technical articles assume that you already know all about them. If you're one of the many who still have a few questions, you could just read past the confusing bits and try to figure it out anyway. And if you have a lot of time, you can start searching through Microsoft's documentation:

  • "A Module is a portable executable file, such as type.dll or application.exe, consisting of one or more classes and interfaces."
  • "A Class statement defines a new data type."
  • "The Structure statement defines a composite value type that you can customize."

Right, then. Any questions?

To be a bit more fair to Microsoft, they have pages and pages (and more pages) of information about all of these that you can wade through. And they have to be as exact as possible because they set the standard. In other words, Microsoft's documentation sometimes reads like a law book because it is a law book.

But if you're just learning .NET, it can be very confusing! You have to start somewhere. Understanding the three fundamental ways that you can write code in VB.NET is a good place to start.

You can write VB.NET code using any of these three forms. In other words, you can create a Console Application in VB.NET Express and write:

Module Module1
   Sub Main()
      MsgBox("This is a Module!")
   End Sub
End Module
Class Class1
   Sub Main()
      MsgBox("This is a Class")
   End Sub
End Class
Structure Struct1
   Dim myString As String
   Sub Main()
      MsgBox("This is a Structure")
   End Sub
End Structure

This doesn't make any sense as a program, of course. The point is that you don't get a syntax error so it's "legal" VB.NET code.

These three forms are the only way to code the queen bee root of all of .NET: the object. The only element that interrupts the symmetry of the three forms is the statement: Dim myString As String. That has to do with a Structure being a "composite data type" as Microsoft states in their definition.

Another thing to notice is that all three blocks have a Sub Main() in them. One of the most fundamental principals of OOP is usually called encapsulation. (See my discussion of OOP and encapsulation by clicking here.) This is the "black box" effect. In other words, you should be able to treat each object independently and that includes using identically named subroutines if you want to.

On the next page, we dive into the most important object form, the Class, and also the Module.

  1. About.com
  2. Technology
  3. Visual Basic
  4. Using VB.NET
  5. Modules, Structures, and Classes

©2014 About.com. All rights reserved.