Chapter 3. Application Organization

Introduction

This chapter shows you how some of the object-oriented programming (OOP) features in Visual Basic 2005 are used to build Visual Basic applications. These features include class constructors, namespaces, and support for overloading. While you will spend most of your coding life writing the basic logic of your functions, properties, and Sub procedures, you wouldn’t be able to do it without the basic container systems introduced here.

3.1. Creating a Code Module

Problem

You would like to add some general methods and fields that are accessible to your entire application.

Solution

Add a code module—a construct that is similar to a class, but uses the Module key-word instead of Class—to your application.

Discussion

Visual Basic includes three major code and value containers: classes, structures, and modules. All three types are based on the core definition of a class, but there are times when you’ll want to choose one over another. Modules are useful for storing functions, subroutines, constants, and variable fields that are considered “global” to your entire application. In pre-.NET versions of Visual Basic, most nonform-specific code was stored in a similar “module file” (with a " .bas” file extension). Modules in .NET provide some of that same functionality but in an object-oriented context.

If you’ve already created a new project or opened an existing project in Visual Studio, you can add a new module through the Project → Add Module menu command. ...

Get Visual Basic 2005 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.