Microsoft Visual Basic 2010 Step by Step eBook

(Tina Meador) #1

Chapter 16 Inheriting Forms and Creating Base Classes 403


The Add New Item dialog box gives you the opportunity to name your class. Because
you can store more than one class in a new class module, you might want to specify
a name that is somewhat general.


  1. Type Person.vb in the Name box, and then click Add.


Visual Studio opens a blank class module in the Code Editor and lists a file named
Person .vb in Solution Explorer for your project, as shown here:

Now you’ll type the definition of your class in the class module and learn a few new Visual
Basic keywords. You’ll follow four steps: declare class variables, create properties, create
a method, and finally, create an object based on the new class.

Step 1: Declare class variables
n Below the Public Class Person program statement, type the following variable
declarations:

Private Name1 As String
Private Name2 As String
Here, you declare two variables that will be used exclusively within the class module to
store the values for two string property settings. I’ve declared the variables by using the
Private keyword because, by convention, Visual Basic programmers keep their internal
Free download pdf