Sams Teach Yourself Visual Basic 6 in 24 Hours

Sams Teach Yourself Visual Basic 6 in 24 Hours

By Greg Perry

Where's the Code?

This lesson began by describing code and event procedures in detail, and yet not a word has been mentioned about those topics for several pages. The code is there as a module file, as you can see from the Project Explorer window. Actually, the interest calculation program contains two sets of code.

Controls cannot have the same name if you place them on the same form, but two forms might contain controls with the same name. A control name goes with its parent form. For example, an application might contain an About dialog box and a form that displays account information. Both forms can have a command button named cmdExit that closes the form's window. Each form contains its own code, called the form module, that manages and responds to the controls on that form. You won't always put code in a form's form module, but you often will.

The Project window's Modules entry also is a file with code in it. A module file that lies outside a form module is often called a standard module. You'll place event procedures for forms in the forms' form modules and you'll place common routines that work on all the forms in a standard module file that lies outside the form module but still in the project.

You enter, edit, and view the language of VB in the Code window.

Visual Basic always presents you with VB code in the Code window. A Code window acts a lot like a simple text editor or word processor, in that you can insert, delete, copy, cut, and paste text. Despite the graphical nature of applications and the controls, the code you write to tie things together is still in text.

Take a brief look at the application's single module's Code window by double-clicking the Project window's Module1 entry. Visual Basic opens the module's Code window, as shown in Figure 2.5.

02fig05.jpg

Figure 2.5 The module's Code window.

Code appears in the Code window in various colors to indicate the purpose of the code. As you learn the Visual Basic language, you will better understand why some code is green and some black. Scroll down through the Code window. Don't worry about understanding much or anything about the Code window at this time. As you can see, much of the Code window contains words in English, but the structure might seem completely odd if you've never programmed before. By the time you finish this 24-hour tutorial, you will understand the entire program and be able to speak the Code window's language fluently.

Click Close to close the module's Code window (not VB!) for now. When you close the Code window, make sure that you see the Interest form before you start the next section. If you don't see the Interest form, simply double-click the frmInterest form in the Project window.

Share ThisShare This

Informit Network