Chapter Five

Object-Oriented Programming

Perhaps the most important advanced features in Visual Basic are those that allow you to do true object-oriented programming (OOP). This is a huge topic, and indeed many pages of Microsoft's manuals deal with this important subject in great detail. Instead of repeating all these details, in this chapter I'll highlight the main concepts, provide simple code examples, and give you a foundation from which to further your studies.

Object-oriented programming in Visual Basic is a fascinating subject. Class modules let you structure your applications in ways that you never could before, collections provide a way to flexibly organize and structure the objects you create, and ActiveX technology provides the mechanism to share and use objects across applications. You'll find yourself able to grasp the organization of much bigger projects and to keep this structure clearly in mind as you work with objects. Team programming and single programmer projects alike are made easier by this object-oriented approach.

There's a lot of new information to be absorbed when you first get into the object-oriented programming aspects of using Visual Basic. With a little persistence, and by experimenting with the examples provided in this book or elsewhere, you'll soon start to get the hang of it. For me, the moment of enlightenment came when I suddenly realized that creating objects is actually a lot of fun!

In this chapter, we'll create a sample object and a sample ActiveX EXE, and we'll take a look at one way to work with collections of objects. We will also discuss polymorphism and friend methods.