Sams Teach Yourself Visual Basic 6 in 24 Hours

Sams Teach Yourself Visual Basic 6 in 24 Hours

By Greg Perry

Naming Menu Options

You should follow a standard naming convention when naming menu options.

The event procedures within any Visual Basic application reference menu options by their menu option names. Preface all menu items, both menu bar and pull-down menu items, with the mnu prefix so that you can easily distinguish menu commands from variables and from the other controls as you work within the application's code.

As you add pull-down options to the menu bar items, preface each option with the mnu prefix as well as the name of the menu bar command, and then append the name of the pull-down menu's item. The File | Exit item would be named mnuFileExit, View | Normal would be named mnuViewNormal, and so on. The names then clearly describe the menu items that they represent. If a submenu appears, append its item name to the parent's name (for example, mnuViewNormalFull).

Follow these steps to complete the creation of a menu bar:

  1. Click the Menu Editor's Next command button to inform Visual Basic that you want to add the next item. The lower window's highlight bar drops down to the next line in preparation for the next menu item. The buttons right above the lower window control the addition, insertion, and deletion of menu items from the menu you are building.
  2. Type &Edit at the Caption text box and press Tab. Name this second menu bar item mnuEdit. Click the Next command button to prepare the Menu Editor for the next menu bar item.
  3. Type &View and press Tab to move the focus to the Name text box. Type mnuView and select Next to prepare for the final menu item.
  4. Type &Help and press Tab to move the focus to the Name text box. Type mnuHelp. Your screen should look like the one in Figure 17.4.
    17fig04.gif

    Figure 17.4 The menu bar is now complete with four options.

Close the Menu Editor by pressing Enter or clicking the OK command button. Immediately, Visual Basic displays the new menu bar across the top of the application's Form window, as shown in Figure 17.5. The menu bar is the result of your efforts with the Menu Editor.

17fig05.gif

Figure 17.5 The Form window's new menu bar.

Obviously, the menu is incomplete. The menu bar exists, but no options pull down from the menu bar. You're now ready to add the individual pull-down options to the menu. The next section explains how to complete the File pull-down menu.

Share ThisShare This

Informit Network