Share via


Visual Basic Concepts

Creating Your Own Classes

If you're an experienced programmer, you already have a library of useful functions you've written over the years. Objects don't replace functions — you'll still write and use utility functions — but they provide a convenient, logical way to organize procedures and data.

In particular, the classes from which you create objects combine data and procedures into a unit. The following topics explain how this increases the robustness of your code, and how it leads to new ways of programming.

  • Classes: Putting User-Defined Types and Procedures Together   Classes are user-defined types with an attitude. Encapsulation puts code and data in the same module, giving rise to objects that can protect and validate their own data.

  • Customizing Form Classes   You've been creating classes for years — every time you designed a form. This has interesting consequences for form design.

  • Class Module Step by Step   A short introduction to class modules, including class creation, creating objects from classes, and the rules of object lifetime.

  • Debugging Class Modules   Describes the Break in Class Module error trapping option, plus the ALT+F8 and ALT+F5 keystrokes for stepping or running past errors.

  • Life Cycle of Visual Basic Forms   The lifetimes of forms, and the controls they contain, follow slightly different rules than those that govern other objects.

  • Class Modules vs. Standard Modules   There are significant differences between class modules and standard modules. Understanding these will help you write better code for your objects.