Introduction to Computer Programming IT-104 - PowerPoint PPT Presentation

About This Presentation

Introduction to Computer Programming IT-104


Objectives Introduction Creating a Function Creating a Sub General Code Modules Exit String Functons Passing Arguments Introduction to Computer Programming IT-104 – PowerPoint PPT presentation

Number of Views:587
Avg rating:3.0/5.0
Slides: 53
Provided by: ittesi
Learn more at:


Transcript and Presenter's Notes

Title: Introduction to Computer Programming IT-104

Creating a Function
Creating a Sub
Code Modules
String Functons
Passing Arguments
  • Introduction to Computer Programming IT-104
  • Unit Eight Menus and Toolbars

  • Understand the need for Menus and Toolbars
  • Understand the different levels of a Menu object.
  • Understand what a Pop-up menu is and how to
    implement one in an application.
  • Understand what a Toolbar is and how to create

  • Understand the difference between a toolbar and a

  • Thus far in our study of programming in the
    Windows environment, we have used command buttons
    to initiate event procedures for a particular
  • This is a useful device, but there are
    limitations to this process.
  • When a form is used to control and coordinate a
    complex and lengthy set of functions and
    procedures, it might require so many command
    buttons to initiate these procedures as to make
    it impossible for all of the functions to be
    implemented simply due to the available space on
    the form.

  • Additionally, a command button drives the caption
    that will be assigned by the programmer again
    due to the physical size of the button. A
    lengthy caption would require a very large
    command button to properly display the caption.
  • Menus are a logical solution to this problem. A
    menu allows the programmer to logically group
    similar functions together on the menu, and
    greatly reduces the size necessary for displaying
    the function or procedure.

Menus vs. Command Buttons
  • Menus
  • Advantages
  • Allow a very large selection of items on a given
  • Allow the logical grouping of these items in a
    defined tree-like structure.
  • Are visible in a very compact form when not in
    use, thus creating less visual distraction to the
  • Conserve form space for other controls and uses.

Menus vs. Command Buttons
  • Menus
  • Disadvantages
  • Selecting functions or procedures might entail
    searching the menu structure to find them.
  • Directly accessing a menu item not in the main
    pad level is impossible with the accelerator (hot
    key) key approach.
  • Requires more planning for implementation.
  • Cannot accept focus as an object.

Menus vs. Command Buttons
  • Command Buttons
  • Advantages
  • Always visible on the form.
  • Provide a quick overview of what the form can do.
  • Can be accessed using accelerator (hot key) key
    methods within Visual Basic.
  • Can accept focus as an object.
  • Generally preferred by data input clerks over
    menu/keystroke combinations to activate items.

Menus vs. Command Buttons
  • Command Buttons
  • Disadvantages
  • Consume form space that might be utilized to
    better effect, if it were available.
  • The size of the button is dictated by the
  • The buttons become cumbersome to manage as the
    number of them exceeds 6.
  • As the number of buttons increases, the visual
    clutter they can produce on the form can distract
    and confuse the user.

Creating a Menu in Visual Basic
  • A menu can be added to most forms in a project.
  • To add a menu, the form object itself must be
    visible on the IDE work surface. You cannot edit
    or create a menu while you are in the code
  • Before you invoke the menu editor, decide by
    creating a diagram on paper what you want the
    menu to do. This will help you properly organize
    the logical relationships that exist among menu
  • The next slide shows an application created to
    demonstrate common menu items and functions.

A Sample Menu
A Sample Menu
  • Notice the compact nature of the menu in the
    preceding slide.
  • The size of the primary menu belies its
  • Selecting the File pad will reveal the sub-menu
    structure of that primary menu pad as shown on
    the following slide.

A Sample Menu
A Sample Menu
  • Note the logical grouping of common file
  • Creating a new file, opening an existing file,
    saving, and saving as are grouped together.
  • A separator bar is used to visually create a
    space between the first group of functions, and
    the Print function.
  • The Print function has an arrow head at the
    right of the pad indicating that there is a menu
    option, known as a fly-out menu available to
    enumerate the print functions.

A Sample Menu
  • Note also that the Exit pad is separated from
    the other menu items by a separator bar.
  • The separator bar serves to visually separate
    objects, making them easier to organize with the
  • It also serves to create additional space between
    menu items, thus minimizing the chance that a
    user who is challenged physically will
    accidentally select the wrong menu pad.
  • The next slide shows the fly-out menu displayed
    when the Print pad is selected.

A Sample Menu
A Sample Menu
  • Note how much more compact this process is than
    trying to implement a command button structure to
    accomplish the same functionality.
  • Note again that the Options pad of the print
    fly-out has an arrow head indicating that there
    are additional menu functions available with this
  • Selecting the Options pad displays the fly-out
    menu shown on the following slide.

A Sample Menu
A Sample Menu
  • The Options pad gives another sub-menu with yet
    another fly-out menu option.
  • Selecting the Format pad displays the sub-menu
    shown on the next slide.

A Sample Menu
A Sample Menu
  • There are no more fly-outs, so this is as far as
    our menu goes depth-wise.
  • A programmer can use this process to his best
    advantage to organize objects.
  • The limit to the process is the actual screen
    resolution and size for display.
  • As the objects display right, if an additional
    level would cause the menu to display off the
    right margin of the screen, the next level will
    fold back over on top of existing menus, thus
    partially or wholly obscuring them from view.

Adding code to a menu object
  • By navigating the same menu structure at design
    time and clicking the Size pad at the terminus
    of the menu structure as shown on the following
    slide will produce a click procedure for the menu
    item selected.
  • Notice the menu name is included with the sub
    created, following the convention we have
    observed for event procedure naming in Visual
    Basic (ObjectName_Event()).

Adding code to a menu object
Adding code to a menu object
Adding code to a menu object
  • Code can now be added to this menu option to
    execute whatever statements the programmer needs
    to create the desired functionality.
  • All menu options are coded in a similar manner.
  • It is important to point out that only menu items
    at the end of the tree structure, such as this
    one is can have a sub procedure attached to them.

Adding code to a menu object
  • It is not possible, for example, to have a sub
    procedure for the Format pad itself since it
    contains a sub-menu.
  • Once a sub-menu is added to an existing menu pad,
    it can no longer support a sub-procedure called
    under its own name, and if such a procedure
    already exists, it will no longer execute.

Creating the Menu Structure
  • As described previously, the form object must be
    visible, on top of all objects in the VB IDE in
    order to access the menu editor.
  • To access the editor, select ToolsMenu Editor
    and you will be confronted with the dialog form
    shown on the next slide.

Creating the Menu Structure
Creating the Menu Structure
  • The standard properties that we have come to
    expect from objects are displayed.
  • There is a Caption property which determines
    what is displayed on the menu pad for the object.
  • All menu pads must have a name conforming to the
    same naming conventions we have discussed
  • The prefix for every menu pad is mnu.

Creating the Menu Structure
  • To add an item, enter the desired caption, then
    the name, again being sure to prefix it with mnu.
  • The next slide shows the same dialog after we
    have added an File pad.

(No Transcript)
Creating the Menu Structure
  • The menu pad can be part of an array by simply
    setting the Index value in the text box.
  • A shortcut key can be assigned to pads that are
    not part of the primary menu structure (visible
    at the top of the form at design or run time).
  • The shortcut key gives the user and programmer
    quick and easy access to commonly used menu
    functions that might be buried many levels deep
    in the menu structure.

Creating the Menu Structure
  • Every menu pad can have an accelerator (hot key)
    assigned to it by simply placing an ampersand in
    front of the desired character.
  • Pressing the OK button on the menu editor will
    result in the form now having a menu with one pad
    as shown on the following slide.

Creating the Menu Structure
Creating the Menu Structure
  • Note that the F in file is now an accelerator
  • Either clicking the File pad or pressing the
    key combination Alt F will cause the pad to be
  • A shortcut key was not assigned because File is
    a primary menu pad, and as such cannot have a
    shortcut key assigned to it.
  • To add additional items we invoke the menu editor
    and simply insert items by using the Insert

Creating the Menu Structure
  • If the cursor is positioned within the existing
    items, a blank line will be inserted above the
    cursor allowing you to add an item.
  • By moving the cursor with either the mouse or the
    Next button, you can insert menu items wherever
    you wish.

  • To make any pad a part of a sub menu, press the
    right arrow key, and the editor will now indent
    the item, tabbing four places to the right of the
    item above the pad, and displaying a diaresis
    (four periods or dots in succession . ).
  • The menu item is now dependent on the item above
    it in the menu tree, and must be accessed by
    navigating through the primary item, unless you
    assign a shortcut key to it.
  • The next slide shows how to add a New pad to
    our File pad as a sub-menu option.
  • We will add a shortcut key using the combo box to
    select the F3 function key as our choice.

(No Transcript)
  • Note the name of the pad, mnuFileNew.
  • It is convention to always prefix the name of the
    invoking menu tree structure to the name of the
    new pad.
  • Note also the visual display of the New pad
    underneath the File pad, but indented to
    clearly denote that it is a sub-menu item
    attached to File.
  • There are only those combinations displayed in
    the combo box available as shortcut keys.
    Programmers are not allowed to define their own
    combinations in Visual Basic outside of these.
  • The result of our addition to the form is shown
    on the following slide.

  • The New pad is a sub-menu option that can only
    be displayed and accessed by either clicking the
    File pad first, or by pressing the F3
    function key, and the shortcut key we defined in
    the menu editor is displayed to the right of our
    sub-menu option.
  • The New pad can also be accessed using the
    accelerator keys that we defined at both menu
  • By pressing Alt F and then the N key, we
    can achieve the same results.

  • The next four slides show a fully developed menu
    structure utilizing multiple sub-menus, shortcut
    keys, accelerator keys and incorporating a pad
    that will become a pop-up menu. (more on that
  • Unfortunately, the menu editor dialog cannot be
    resized or customized in any significant way, and
    once the number of menu items exceeds the display
    capacity of the list box, the scroll bar is
    introduced and it is necessary to scroll down to
    display the remaining contents of the menu list

(No Transcript)
(No Transcript)
(No Transcript)
(No Transcript)
Popup Menu
  • A Popup menu is one that appears generally when
    the user triggers it through an event, such as
    right-clicking the mouse, and is not visible at
    other times.

  • Understand the need for Menus and Toolbars
  • Understand the different levels of a Menu object.
  • Understand what a Pop-up menu is and how to
    implement one in an application.
  • Understand what a Toolbar is and how to create

  • Understand the difference between a toolbar and a

LAB Work
  • Create an application template with a main form
    having a menu.
  • Add an About dialog form from the Add Form
  • Add a Splash form from the Add Form dialog.
  • Create the necessary code to bind the three forms
    together in a seamless application.

  • Read Chapter 10.

Next Week
  • Using the File System Object in Visual Basic.
  • More on files and storage.
Write a Comment
User Comments (0)