• UNIT8: Introduction to Visual basic

    KeyUnitCompetency.

    To be able to describe a Visual Basic Integrated Development (VB-IDE) and write a program in Visual Basic.

    INTRODUCTORY ACTIVITY

    Read the bellow scenario:
    ABC hotel provides different services to its customers such as business center, room services, restaurant and others. For the room services, front desk office receives clients and information is collected as shown below:

    Observe the above picture and answer the following questions:

    1. What do you think of the above figure?

    2. Explain why ABC hotel needs to collect data of each client

    3. Investigate why the figure hold these words such :Add new ,Display and Exit

    4. Which programming language would use to design the above figure?

    5. Can you try to design the above figure?

    In programming, the above scenario requires specific programming language that enables us to enter data using forms and save the data in database to receive them whether is a need. This unit will enable to build a simple desktop application for a real life situation.

    8.1. Understanding Visual Basic.

    LEARNING ACTIVITY. 8.1

    1. Click on start button, All programs, Microsoft Visual basic 6.0, Microsoft visual basic 6.0. What is the name of the window that has opened?

    2. Make double click on standard EXE. What do you observe?

    3. Differentiate desktop and web applications.

    8.1.0. General introduction

    VISUAL BASIC is a high level and Event-driven Programming Language which evolved from the earlier Desk Opening System (DOS) version called BASIC. (BASIC means: Beginners’ All-purpose Symbolic Instruction Code). Visual basic for DOS and Visual Basic for Windows were introduced in 1991 and
    evolved through the years to give Visual basic 3.0(in 1993), Visual basic 4.0 (in 1995) Visual basic 5.0 (in 1996) and now we use Visual basic 6.0 version released in 1998.

    Visual basic 6.0 has the following advantages:

    • It is easier for the user to minimize code writing.

    • The user will become more familiar with visual approach for other visual languages.

    • It provides Input box and Output box as interactive windows with user.

    • It is very easy program language compare with other.

    8.1.1. Definition of terms

    d. Graphical User Interface.

    A graphical user interface (GUI) is an interface through which a user interacts with electronic devices such as computers, hand-held devices and other appliances. GUI representations are manipulated by a pointing device such as a mouse, trackball, stylus, or a finger on a touch screen.

    The need for GUI became apparent because the first human/computer text interface was through keyboard text creation by what is called a prompt (or DOS prompt). Commands were typed on a keyboard at the DOS prompt to initiate responses from a computer. The use of these commands and the need for exact spelling made this interface difficult to use and inefficient.

    A GUI uses a combination of technologies and devices to provide a platform that user can interact with, for the tasks of gathering and producing information. Graphical user interface (GUI) is different from command line interface (CLI) or command language interpreter as command line interface (CLI) enables users to type commands in a terminal or console window to interact with an operating system. Users respond to a visual prompt by typing a command on a specified line (MLI), and receive a response back from the system. Users type a command or series of commands for each task they want to perform.

    e. Desktop application

    A desktop application is a computer program that runs locally on a computer device, such as desktop or laptop computer, in contrast to a web application, which is delivered to a local device over the Internet through browser from a remote server. Different user environments can impact whether a desktop or a web application is the best solution for your needs.

    Difference between desktop and web applications.

    Desktop applications

    • They must be developed for and installed on a particular operating system.

    • Have strict hardware requirements that must be met to ensure that they function correctly.

    • Updates to the applications must be applied by the user directly to their installation, and may require hardware upgrades or other changes in order to work.

    Web applications

    • A web application is any computer program that performs a specific function by using a web browser.

    • The user accesses the application using the web browser and works with resources available over the internet, including storage and CPU processing power.

    • This approach allows for “thin clients” (machines with limited hardware capabilities) to provide access to complex applications delivered from a centralized infrastructure.

    f. Event oriented programming.

    Event oriented programming is a paradigm in which the flow of program is determined by events, such as user actions (mouse clicks, key presses), sensor outputs or messages from other programs is common used in graphical user interfaces and other applications like Web applications, JavaScript, C#.
    Other types of programming paradigm are: C, C++
    • Procedural programming used by Basic, Fortran and COBAL
    • Declarative programming used by Prolog

    Event oriented programming using Visual Basic

    Visual Basic is Event oriented programming because of the following

    • The programmer needs to write code that performs some tasks in response to certain events.

    • Has events that occur by mouse clicking and moving or keyboard stokes (Some of the events are load, click, double click, drag and drop, pressing the keys and more.)

    • Focus on the use of Graphical User Interface.

    • The events usually comply but not limited to the user’s inputs.

    8.1.2. The Features of Visual Basic

    Visual Basic has the following features:

    1. Data Access Features: this allows programmers to develop database front end applications and server side components for most popular database formats including MS SQL and other Databases.

    2. Active X Technologies: that allows programmers to use the functionality provided by other applications, such as MS Office and other windows applications.

    3. Internet capabilities make it easy to provide access to documents and applications across internet server applications.

    4. Your finished application is a true executable (.exe) file that uses a visual Basic Virtual Machine that you can freely distribute.

    8.1.3 Standard EXE Visual Basic Application

    Using Visual Basic one can develop one of these main projects as indicated in the
    screen below:
    1. Standard Exe project is a typical application in which can use the database
    manipulation.

    A standard exe application is one that is created using Standard EXE project. It is the most widely used Project type using VB6. Standard EXE application is normally the most widely used among the available Project types in Visual Basic. Stand-alone

    programs have an .EXE file extension. A standard EXE application is normally used
    when you want to develop a stand-alone application. Examples include calculators,
    text editors, and other similar applications.

    8.1.4. Starting VB 6.0

    Opening application of visual basic 6.0

    On start up, Visual basic 6.0 will display a dialog box, and one can choose to start a new project, open a new existing project, or select a list of recently opened programs.


    Application activities (8.1)

    1. With examples, discuss the difference between the following:

    a. Graphical User Interface and Command User Interface.

    b. Desktop application and Online application.

    2. State the process followed to start up Visual basic 6.0.

    8.2 Visual Basic Standard EXE Integrated Development Environment(VB-IDE)

    Learning Activity 8.2

    1. Observe the figure and name the objects labeled A, B, C, D, E and F

    a) Visual basic Integrated Development Environment describes the interface
    and environment that we use to create our applications in VB.

    It is called integrated because we can access virtually all of the development tools
    that we need from one screen called interface. The IDE is also commonly referred to
    as the design environment, or the program.

    Project description in standard exe. Project window.

    To design a form window in Visual basic integrated development environment, first
    install Microsoft visual basic 6.0 into PC, and follow the following in order to use it.
    Start>all program> Microsoft visual basic 6.0> Dialog Box >Standard EXE> formwindow
    appear.From the New Project window we can select new, existing and recent
    project.The Standard EXE Project looks like this:

    This is the main IDE window of Visual Basic. The following are components of the standard exe.windows.

    8.2.1 Tool Box

    Items of tool box are used to design the application interface. These items are
    called Controls and are shown in the image below.

    8.2.2 Form window

    The form window is the window or background, where the user can design his form using various controls from the toolbox

    Each standard form has a code window in which the user can write to direct the behavior of a control. You open the code window by double clicking on a form or a control. If you double click a form, you will be taken to a procedure for the form, but once the code window is open, you can go to any procedure for any object on the selected form.

    The codes are of two Categories:

    Declaration is written before any procedure in the code window.
    Statements. The user selects the required event then code statements are written inside these event procedures.

    8.2.4 Project explorer

    Contains forms related to your application, it also contains code modules and classes.

    8.2.5 Properties Window

    Properties are the attribute of controls. Every object has properties, for example a Pen, has its Color, Metal Type, Ink Color, Type etc. In the same manner every control in VB has many properties which are applied by using the property fields in property box . Some properties are read only, which means the values of such properties can’t change using code, while others are Read and Write. You can move Property window any side of VB IDE Window, can appeal using tool bar or by Pressing F4.

    It is also possible to change the properties at runtime to give special effects such as change of color, shape, animation effect and so on.

    8.2.6 Form Layout Window

    The Form Layout window is a visual design tool which is used to control the placement of the forms in the windows environment when they are executed especially when you have more than one form in your program, To position a form in the Form Layout window, simply drag the miniature form to the desired location in the window.

    8.2.7 Menu Bar

    This is where you can select actions to perform on all your project files and to access help. When a project is open extra menus of project, build and data, are shown in addition to the default menu selection of File, edit, View, Debug, tools, window and Help.

    Application activities 8.2

    1. Name five items on VB toolbox.

    2. List two boxes that make up Visual Basic IDE?

    8.3 Visual basic controls

    a) Uses of properties window

    Learning activities (8.3.1)

    1. Design a form and call it “NDI UMUNYARWANDA” and have the three labels with three textbox. As well as the properties of label are:

    Name: lblfirstname, lbllastname, and lblnationarity respectively.

    Appearance: run time with 3D effects.

    Caption: First Name, last Name and Nationality. Respectively

    Font: (font face Bold, font style Time New roman, size 14 and effects)

    Forecolor: It returns foreground color of a label

    Height: 1000.

    Width: 2000

    Backcolor: Active border.

    Borderstyle: Fixed Single-With border)

    Backstyle: Opaque

    • And the textbox as

    Name: txtfirstname, txtlastname, and txtnationarity respectively.

    Caption: Null in all

    Font: (font face Bold, font style Time New roman, size 14 and effects)

    Height: 730.

    Width: 3000

    8.3.1 Definition of form.

    Form is the shape, visual appearance, or configuration of an object. In a wider sense, the form is the way something is or happens. Form may also refer to: Form (document), a document (printed or electronic) with spaces in which to write or enter data.

    8.3.2 How to design a form in Visual Basic

    To design a form in visual basic use the controls which are available in the Tool Box in the left side of the project window. Use the following steps for each control that you want to add on the form:

    Step 1: In the Tool Box, choose a control that you want andClick on it.

    Step 2: Drag and draw a control in the form using mouse.

    Step 3: Change state for Specific control like size etc.

    8.3.3 properties Window

    Definition of Properties Window.

    Properties Window is used to change the state of each control using particular properties associated with each control.

    How to use Properties Window.

    Before writing an event procedure for the control to response to a user’s input, you have to set certain properties for the control to determine its appearance and how it will work with the event procedure. You can set the properties of the controls in the properties window or at runtime.

    Consider the following picture



    Figure 8.15 above is a typical properties window for a form. You can rename the form caption to any name that you like best. In the properties window, the item appears at the top part is the object currently selected (in Figure 8.15, the object selected is Form1). At the bottom part, the items listed in the left column represent the names of various properties associated with the selected object while the items listed in the right column represent the states of the properties. Properties can be set by highlighting the items in the right column then change them by typing or selecting the options available. For example, in order to change the caption, just highlight Form1 under the name Caption and change it to other names. You may also try to alter the appearance of the form by setting it to 3D or flat. Other things you can do
    are to change its foreground and background color, change the font type and font
    size, enable or disable minimize and maximize buttons and etc.

    Application activity 8.3.1

    Q1. Which property used to change state of a control?

    a) Design a form using a control.

    Learning activities (8.3.2)

    Observe the figure below:
    Using the toolbox design the above form.


    A control: is a tool you use to create objects on a Visual Basic form. You select controls from the toolbox and use the mouse to draw objects on a form. You use most controls to create user interface elements, such as command buttons, image boxes, and list boxes.

    • Properties of a control.

    Before writing an event procedure for the control to respond to an event, you have to set certain properties for the control to determine its appearance and how it will work with the event procedure. You can set the properties of the controls in the properties window or at design time. Other things you can do are to change its foreground and background color, change the font type and font size, enable or disable minimize and maximize buttons etc. Here are the important points about setting up control properties:

    • Caption Property of a control should be clearly defined so that a user knows what to do with control

    • Use a meaningful name for property as it is easier to write and read the event procedure and easier to debug or modify the program later.

    • One more important property is whether to make the control enabled or not.

    • You should also consider making the control visible or invisible at design time, or when should it become visible or invisible.

    8.3.4 Common controls used in Visual Basic:


    a .Form
    Form is used when you start Visual Basic, a default form (Form1) with a standard grid (a window consisting of regularly spaced dots) appears in a pane called the Formwindow. You can use the Form window grid to create the user interface and to line up interface elements.

    Steps to create Form

    Step 1: Click Project on menu and choose Add form from the list of options


    Step 2: Click Form and click Open

    Step 3: Set the Properties for a form

    Name: Enter the name of the form. It returns the name used to identify form.

    Enabled: form controls can be enabled or disabled on initial execution with the enabled property.

    Appearance: It sets whether or not object is painted at run time with 3D effects.

    Caption: Enter the caption associated with the form. It sets the text displayed as the title of the form.

    Backcolor: Choose background color of textbox .It sets the background color used to display textbox.

    Borderstyle: Choose border style of the form

    Fillcolor: It sets the colour used to fill in shapes, circles and boxes.

    Fillstyle: It returns the fill style of a shape

    Backstyle: Choose background style; Opaque or transparent

    Font: It returns the font of a form.

    Scaleheight: It sets the number of units for the vertical measurement of form.

    Scaleleft: It returns the horizontal coordinates for the left edge of form.

    • Visible shows or hide a control on a form. It sets value that determines whether an object is visible or hidden


    The label is a very useful control for Visual Basic, as it is not only used to provide instructions and guides to the users, it can also be used to display outputs. One of its most important properties is Caption. Using the syntax label.Caption, it can display text and numeric data. You can change its caption in the properties window and also at runtime.

    The following are the steps to add a label on the form.

    Step 1: Click on the label icon on the toolbox

    Step 2: Drag and drop a label control in the form

    Step 3: Set Properties for label

    Name: Enter the name of the label control. It returns the name used to identify object.

    Alignment: It returns/sets the alignment of a label

    Appearance: It sets whether or not object is painted at run time with 3D effects.

    Caption: Enter the caption associated with the label. It sets the text displayed on the form.

    Font: It returns the font of object (font face, font style, size and effects)

    Forecolor: It returns foreground color of a label

    Height: Enter the height of the label.

    Backcolor: Choose background color. It sets the background color used to display label.

    Borderstyle: Choose border style of the label(None-no border or Fixed Single- With border)

    Backstyle: Choose background style; Opaque or transparent

    c. Text Box


    The text box is the standard control that is used to receive input from the user as
    well as to display the output. It can handle string (text) and numeric data but not
    images or pictures. String in a text box can be converted to a numeric data by using
    the function Val(text).
    . Steps to add Textbox
    Step 1: Click on the Textbox icon    on the toolbox

    Step 2: Drag and drop a Textbox control in the form

    Step 3: Set Properties for Textbox such as Name, alignment, appearance, backcolor etc.

    d. Frame


    If you want to create a group of controls that work together, you must first create a frame for the controls. (To do this, use Frame, a Visual Basic toolbox control.) Next, place your controls inside the frame so that they can be processed as a group in your program code and moved as a group along with the frame

    Steps to add Frame:

    Step 1: Click on the Frame icon  on the toolbox

    Step 2: Drag and drop a Frame control in the form

    Step 3: Set Properties for Frame: on this step, you set preferred properties


    e. Radio Buttons/ Option Buttons

    The Option Box control lets the user selects one of the choices. However, two or more Option Boxes must work together because as one of the Option Boxes is selected, the other Option Boxes will be unselected. In fact, only one Option Box can be selected at one time. In computer terminology we call this ‘mutual exclusion’. Therefore, two option box controls are said to be mutually exclusive of each other. When an option box is selected, its value is set to “True” and when it is unselected; its value is set to “False”.

    Steps to add Option Button

    Step 1: Click on the OptionButton   icon on the toolbox

    Step 2: Drag and drop aOptionButton control in the form

    Step 3: Set Properties for Option Button

    f. Check box control

    The Check Box control lets the user to select or unselect an option. When the Check Box is checked, its value is set to 1 and when it is unchecked, the value is set to 0. You can include the statements Check1.Value=1 to mark the Check Box and Check1. Value=0 unmark the Check Box, and use them to initiate certain actions. For example, the program will change the background color of the form to red when the check box is unchecked and it will change to blue when the check box is checked.

    Steps to add CheckBox

    Step 1: Click on the CheckBox  icon on the toolbox

    Step 2: Drag and drop a CheckBox control in the form

    Step 3: Set Properties for CheckBox

    g. Command button

    Command button is a very important control as it is used to execute commands. It displays an illusion that the button is pressed when the user clicks on it. The most common event associated with the command button is the Click event.

    h. List Box
    The function of the List Box is to present a list of items where the user can click and select the items from the list. In order to add items to the list, we can use the AddItem method.

    List Box contains a list of options from which user can choose. In windows the
    Font List box is an example of the use of a list box. The Selected item in a ListBox is

    given by the Textproperty. The sorted property determines whether the items in the
    list box will be sorted or not.

    Adding items to list

    a) Change property list from properties window: Open the list properties window
    and choose list property. Write a list of items to appear in the list box

    i. Combo Box

    The function of the Combo Box is also to present a list of items where the user can click and select the items from the list. However, the user needs to click on the small arrowhead on the right of the combo box to see the items which are presented in a drop-down list. In order to add items to the list, you can also use the AddItem method.

    j. Picture Box

    The Picture Box is one of the controls that used to handle graphics. You can load a picture at design phase by clicking on the picture item in the properties window and select the picture from the selected folder. You can also load the picture at runtime using the LoadPicture method. For example, the statement will load the picture grape.gif into the picture box.

    Picture1.Picture=LoadPicture(“C:\Images\grape.gif”)

    Picture Box is a control used to display images on a VB page. The Picture Box control also supports few functionality of generating advanced drawing.

    k. Image box

    The Image Box is another control that handles images and pictures. It functions almost identically to the picture box. However, there is one major difference, the image in an Image Box is stretchable, which means it can be resized. This feature is not available in the Picture Box. The syntax is as follows:

    l. Timer

    When we need to perform tasks at regular interval we can use Timer . Open a new project and place a timer object on your form. Then locate a label at the center of theform and adjust the size as shown in the figure below. For such a program a better look will beestablished by sizing your form as a pop up window.

    m. File System Controls

    File System Controls are set of controls which help us to add file handling capabilities to our program. They are used together to provide an interface for accessing and exploring drives, folders and files. File system controls can be drive list box, directory list box and file list box.

    1) Drive List Box: The Drive ListBox is for displaying a list of drives available in
    your computer. When you place this control on the form and run the program, you will be able to select different drives from your computer.

    2) Directory List Box: is for displaying the list of directories or folders in a selected drive. When you place this control into the form and run the program, you will be able to select different directories from a selected drive in your computer.

    3) File List Box: This control displays a list of files in the current folder.
    These are important controls even though there are plenty of controls used in VB.

    g. ADO

    ADO (ActiveX Data Objects)is the preferred method for accessing non-Jet tables. ADO and DAO are interchangeable for most things and you are unlikely to experience real timing differences with the two methods. There are some things that ADO cannot do with an Access database that DAO can do.DAO is native to Jet, and on several operations, it might perform a bit faster on Jet than ADO. DAO will contain some methods and properties that are only relevant to Jet, not other databases.

    h. DAO

    DAO(Data Access Objects) was the first object-oriented interface that exposed the Microsoft Jet database engine (used by Microsoft Access) and allowed Visual Basic developers to directly connect to Access tables as well as other databases - through Open Database Connectivity (ODBC).

    3. Design a form “Rectangle” that contains a round rectangle.

    4. What is the most common Event associated with the Command Button?

    8.4. Planning and Developing a Visual Basic program.8

    8.4.1 The process of Planning and Developing a Visual Basic program

    Learning activity 8.4.1
    Consider and observe the following form that contains different controls and help a
    school to calculate the monthly interest according to the borrowed money per month.

    1. What is the role of each control on the form.

    2. Which cause the command button named calculate to find and display           the interest

    3. What happen if you do not find the simple interest?

    4. What can you do if run a program and you are informed that the program contains errors?

    Developing a VB program is mainly done in three steps namely setting up user interface, defining the properties, and creating code.

    a. Draw the interface

    At this step, you will be using the object to design the interface of your application; the controls will be taken from the tool box by dragging it from there to the form designer.

    b. Set properties

    At this stage, you will be setting up properties for your form and controls. Those properties are set from the properties window.

    c. Write the event code.

    Coding is to be done in the code window and you get there by double clicking the object you want to code. Now we double click on the form1, the source code Window for the form1 appears:

    Private Sub Form_Load()
    End Sub

    You just have to write your code between two statements. In order to display the
    output, you have to add Form1.show

    Example 8.4.1: VB application to display the message: “welcome to the world of
    programming:”

    Private sub Form_load()

    Form1.show

    Print”welcome to the world of programming”

    End sub.

    Procedure:

    • Put the pointer on the form 1, right button, properties, go to name and replace form1 by frmvolumecylinder.

    • Go to caption; and replace form1 by Volume of cylinder

    • Go now to toolbox, then choose label (3 times) and if toolbox is not there, go to view then choose toolbox

    • Click once on the label one, right button; properties and replace label1 name by lblradius and the caption by the “Radius

    • Click on the label2, properties and replace the label2 name by lblheight and the caption by “Height”

    • Click on label3, properties and replace the name by lblarea and caption by “Volume”.

    • Then go to toolbox, choose now the textbox (3 times) starting by the first, go to properties and remove.

    • Go to text name and replace the text1, text2 and text3 by txtradius, txtheight and txtvolume respectively.

    • Go back to toolbox and choose command buttons (3 times)

    • Go to properties and replace names command1, command2 and command3 by cmdcalculate, cmdnew and cmdexit respectively captions by Calculate,Newcalculation and Exit.

    Command “Calculate”

    Double click on command button “Calculate” to write the code to calculate the
    area when you click on it at running time.

    Codes:

    Private Sub cmdcalculate_Click()
    txtvolume.Text = 3.14 * Val(txtradius.Text ^ 2) * Val(txtheight.Text)
    End Sub

    Command “New Calculation”

    Double click on the command New calculation to write the code to let you make other calculation when click on it.

    Codes:

    Private Sub cmdnew_Click()
    txtradius.Text = “”
    txtheight.Text = “”
    txtvolume.Text = “”
    End Sub

    Command “Exit”

    And finally Exit command to write the code to end the program when you click
    on it.

    Codes:

    Private Sub cmdexit_Click()
    Unload Me
    End Sub

    Application activity 8.4.1


    1. A. Design a form like above using all possible control and its proportional properties.

    2. Coding a program.

    8.4.2. Debugging Your Code and Handling Errors

    Application activities 8.4.2

    UMWARI is a student in senior five, once planning and developing a visual basic program but in running stage it does not run correctly.

    a. Is it possible to correct it? Explain.

    b. Give appropriate term of correct the challenges faces.

    c. Identify why program does not runand the possible solutions.

    8.4.2 Debugging your Code and Handling Errors

    A. Program error: is a result of bad code in some program involved in producing the erroneous result

    B. Handling errors

    Error handling should be used to process only exceptional situations, despite the fact
    that there is nothing to prevent that programmer from using errors as an alternate
    form of program control.

    These errors can be grouped into three categories:

    • Syntax errors

    • Run-time errors

    • Logic errors

    Syntax errors are grammatical errors in the formulation of statements and are picked up by the interpreter while you are typing in the code (providing the syntax checking option - under environment options - is set to yes).

    Run-time errors these are errors that cannot be detected until the program is running. The syntax of the statements is correct, but once executed they cause a error situation to arise. Examples of run-time errors are attempted division by zero or trying to access a non-existent object.

    Logic errors these are errors that cause the program to behave incorrectly. They generally arise through failure on the part of the programmer to arrive at a correct algorithm for the task. Typical problems might be incorrect ordering of statements, failure to initialise or re-initialise a variable, assignment to an incorrect variable, use of ‘<’ instead of ‘<=’, use of ‘and’ instead of ‘or’, or omission
    of a crucial step in the processing. Logic errors may hide in a program even when it appears to work - they may only surface under certain conditions. This is why careful testing is so important.

    c. Debugging

    Debugging is a process by which you find and resolve errors in your code. To debug code in Visual Basic, consider the ideas suggested below. These techniques can also be applied in different sequences.

    • Print the code, if you find it easier to read code on paper instead of softcopy.

    • Run the application to find trouble spots:

    From the Run menu, choose ‘Start’ to begin running the application. Run until an error stops execution, or halt execution manually when you suspect an error by choosing ‘Break’ from the Run menu. Resolve all compile errors and run-time errors. From the Run menu, choose ‘Continue’ to continue running the application. Once bugs are found try out bug fixes and then make edits by testing individual lines of new or debugged code in the Debug window. Search and replace code

    for all occurrences of an error, checking other procedures, forms, or modules with related code. From the Run menu, choose ‘Restart’ to reset application variables and properties and restart the application from the beginning.

    Debugging tools.

    These are tools designed to help in stopping the execution of a program at specific points, detecting run-time and logic errors and understanding the behavior of errorfree code.

    8.4.4 Building an executable file

    You can make an executable file (.exe) from Visual Basic using the following procedure.
    To make an executable file in Visual Basic

    1. From the File menu, choose Make projectname .exe where projectname is the application name for the project.

    2. Type a file name, or browse through the directories and select an existing file name to overwrite an existing executable with a newer version.

    3. By clicking the Options button, you can also specify a number of versionspecific details about the executable file in the Project Properties dialog box.

    4. If you want to modify the version number of the project, set the appropriate Major, Minor, and Revision numbers. Selecting Auto Increment will automatically step the Revision number each time you run the Make projectname .exe command for this project.

    5. To specify a new name for the application, under Application, type a new
    name in the Title box. If you want to specify a new icon, choose one from
    the list.

    6. You can also enter version-specific commentary on a variety of issues under the Version Information box (comments, company name, trademark and copyright information, and so on) by selecting a topic from the list box and entering information in the text box.

    7. Choose OK to close the Project Properties dialog box, and then choose OK in the Make appname .exe dialog box to compile and link the executable file. You can run the executable file like any other Windows-based application: doubleclick the icon for the executable file.

    8.4.5. Deploying a VB Project

    The Visual Basic Package and Deployment Wizard makes it easy for you to create the necessary cab files and setup programs for your application. Like other wizards, the Package and Deployment Wizard prompts you for information so that it can create any exact configuration.

    There are three ways of starting the Package and Deployment Wizard:

    • Run it from within Visual Basic as an add-in. If run the wizard as an add-in, first set the necessary references in the Add-In Manager to load the wizard. When the wizard as an add-in, Visual Basic work with the project currently open. If work with another project, either open that project before starting the add-in, or use the wizard as a stand-alone component.

    • As a stand-alone component from outside the development environment. Run the wizards as a stand-alone component, prompted choose the project on which working with.

    • Start it in silent mode by launching it from a command prompt. “Running the Wizard in Silent Mode” in this topic for more information. After you start the wizard, a series of screens prompt you for information about your project and let you choose options for the package. Each screen explains how it is
    to be used, including which information is optional, and what information must be  entered before move to the next screen. If it display information on screen, press F1 or click the Help button.

    Note: Save and compile project before running the Package and Deployment Wizard. In most cases, the Package and Deployment Wizard create a package that is ready for deployment. However, if customize packaging process further or provide functionality not supported by the Package and Deployment Wizard, modify the Setup Toolkit Project.

    To start the Package and Deployment Wizard from within Visual Basic

    1. Open the project you want to package or deploy using the wizard. Note If you are working in a project group or have multiple projects loaded, make sure that the project you want to package or deploy is the current project before starting the wizard.

    2. Use the Add-In Manager to load the Package and Deployment Wizard, if necessary: Select Add-In Manager from the Add-Ins menu, select Package and Deployment Wizard from the list, then click OK.

    4. On the main screen, select one of the following options:

    • If you want to create a standard package, Internet package, or dependency file for the project, click Package.

    • If you want to deploy the project, click Deploy.

    • If you want to view, edit, or delete scripts, click Manage Scripts.

    For an introduction to these options, see “The Package and Deployment Wizard.”

    5. Proceed through the wizard screens.

    To start the Package and Deployment Wizard as a stand-alone component

    1. If the project you want to package is open, save it and close Visual Basic.

    2. Click the Start button, and then click Package and Deployment Wizard from the Visual Basic submenu.

    3. In the Project list on the initial screen, choose the project you want to package.

    Note You can click Browse if your project is not in the list.

    4. On the main screen, select one of the following options:

    • If you want to create a standard package, Internet package, or dependency file for the project, click Package.

    • If you want to deploy the project, click Deploy.

    • If you want to view, edit, or delete scripts, click Manage Scripts.

    5. Proceed through the wizard screens.

    Running the Wizard in Silent Mode

    Using scripts, you may package and deploy your project files in silent mode. In silent mode, the wizard runs without your having to attend it to make choices and move through screens. The wizard packages and deploys your project using the settings contained in a script.

    Silent mode is especially useful if you are packaging and deploying as part of a batch process. For example, early in the development of your project, you may use the Package and Deployment Wizard to package your project and deploy it to a test location. You can later create a batch file to perform the same packaging and deployment steps periodically as you update your project.

    To package and deploy in silent mode

    1. Open MS-DOS prompt.

    2. Type the name of the wizard executable, pdcmdln.exe, followed by the path and file name of Visual Basic project, and the appropriate command line arguments.

    3. PDCmdLn.exe C:\Project1\Project1.vbp /p “Internet Package”

    4. /d Deployment1 /l “C:\Project1\Silent Mode.log”

    Note: Can perform packaging and deployment in a single silent session by specifying both the /p and the /d arguments, as shown in the example above. Otherwise, use either /p or /d.

    Note Any file or script name that includes spaces should be enclosed in quotation marks, as shown in the example above.

    Application activities 8.4.2

    1. Describe three types of errors made in Visual basic.

    2. Define the term debugging.

    3. Design a simple calculator which makes addition, division, multiplication and subtraction of two numbers.

    4. Hirwa Eric is a programmer, when he attempts to run his VB code, it generates an error.

    a. Explain why this program generate an error?

    b. Give the strategies Eric must follow in order to solve this problem.

    8.5 WORKING WITH MENUS AND DIALOG BOXES

    Learning activities 8.5

    Observe the following organization structure of a girls’ school and answer the following questions:

    1. As a student of S5 how many levels you pass through in order to reach to head teacher?

    2. Why is it necessary to pass at each level?

    3. Design the above organizational structure into a VB form window use of menus.

    Windows applications provide groups of related commands in Menus. These commands depends on the application, but some-such as Open and Save are frequently found in applications. Menus are intrinsic controls. Visual Basic provides an easy way to create menus with the modal Menu Editor dialog. The below dialog is displayed when the Menu Editor is selected in the Tool Menu. The Menu Editor command is grayed unless the form is visible. And also you can display the Menu Editor window by right clicking on the Form and selecting Menu Editor.

    8.5.1 Multiple Document Interface (MDI).

    The Multiple Document Interface (MDI) is another class of the form that allows you to open Windows within a parent container window to simplify the exchange of information among documents, all under the same roof.

    Applications such as Microsoft office Word and Microsoft office excel are the best examples of MDI, where many documents can be opened simultaneously within the main document.

    To use windows applications that can open multiple documents at the same time and allow the user to switch among them with a mouse-click. Each document is displayed in its own window and all document windows have the same behavior.

    The main Form, or MDI form, isn’t duplicated, but it acts as a container for all the windows, and it is called the parent Window.

    The windows in which the individual documents are displayed are called Child
    windows.

    An MDI application must have at least two Form, the parent form and one or more child forms.

    Each of those forms has certain properties. These can be many child forms contained within the parent form, but there can be only one parent form. The parent form may not contain any controls, while the parent form is open in design mode, the icons on the toolbox are not displayed, but you can’t place any
    controls on the form.

    To create an MDI application, at least two forms are needed in the application: One is the parent or container form and the second is the child form or the form contained within the parent. A single child is required for the simple MDI Projects.

    Procedures:

    • Select New project from the file menu

    • In the case you already have a form ,then in the properties window set the name property to frmchild and its caption to MDI_Child

    • Right-click on the forms folder in the project window

    • Click on add from the MDI form to create the MDI Parent form.

    • Select MDI form from the Add MDI form dialog

    • In the Properties window set the name property to frmMDI and the caption property to MDI_Parent.

    • On the project menu, select project1.properties, set the startup object list to

    frmMDI. In the Case you omit this; the application will start with the child form.

    Select the frmchild from the project Explorer

    Set the form’s MDI child property to true in the properties window. This will cause this form, which is the child, to rest inside the MDI Parent container.

    • Save project as from the file menu and save the form as MDI.frm and project as MDI.vbp

    8.5.2 Creating Menus

    Menus, which are located on the menu bar of a form, contain a list of related commands. When you click a menu title in a Windows-based program, a list of menu commands should always appear in a well-organized list.

    Most menu commands run immediately after they are clicked. For example, when the user clicks the Edit menu Copy command, Windows immediately copies information to the Clipboard. However, if ellipsis points (…) follow the menu command, Visual Basic displays a dialog box that requests more information before the command is carried out.

    This section includes the following topics:

    • Using the Menu Editor

    • Adding Access and Shortcut Keys

    • Processing Menu Choices

    8.5.3 Using The Menu Editor

    The Menu Editor is a Visual Basic dialog box that manages menus in your programs. With the Menu Editor, you can:

    • Add new menus

    • Modify and reorder existing menus

    • Delete old menus

    • Add special effects to your menus, such as access keys, check marks, and keyboard shortcuts.

    See the Figure below for Menu editor Window:

    Creating Menu Command Lists

    To build lists of menu commands, you first need to create the menus and then add them to the program menu bar.

    To create a list of menu commands on a form

    4. Click the form itself (not an object on the form).

    5. On the Visual Basic toolbar, click the Menu Editor icon, or select Menu Editor from the Tools menu.

    6. In the Caption text box, type the menu caption (the name that will appear on the menu bar), and then press TAB.

    7. In the Name text box, type the menu name (the name the menu has in the program code). By convention, programmers use the mnu object name prefix to identify both menus and menu commands.

    8. To add the menu to your program menu bar, click next. The Menu Editor clears the dialog box for the next menu item. As you build your menus, the structure of the menus and commands appear at the bottom of the dialog box.

    9. In the Caption text box, type the caption of your first menu command.

    10. Press tab, and then type the object name of the command in the Name text box.

    11. With this first command highlighted in the menu list box, click the right arrow button in the Menu Editor. In the Menu list box, the command moves one indent (four spaces) to the right. Click the right arrow button in the Menu Editor Dialog box to move items to the right, and click the left arrow button to move items to the left.

    12. Click Next, and then continue to add commands to your menu.

    The position of list box items determines what they are:


    To add more menus

    1. When you’re ready to add another menu, click the left arrow button to make the menu flush left in the Menu list box.

    2. To add another menu and menu commands, repeat Steps 3 through 9 in the preceding procedure.

    3. When you’re finished entering menus and commands, click OK to close the Menu Editor. (Don’t accidentally click Cancel or all your menu work will be lost.) The Menu Editor closes, and your form appears in the programming environment with the menus you created.

    Adding Event Procedures After you add menus to your form, you can use event procedures to process the menu commands. Clicking a menu command on the form in the programming environment displays the event procedure that runs when the menu command is chosen. You’ll learn how to create event procedures that process menu selections in Processing Menu Choices.

    8.5.4 Adding Access and Shortcut Keys.

    Visual Basic makes it easy to provide access key and shortcut key support for menus
    and menu commands.

    Access and Shortcut Keys

    The access key for a command is the letter the user can press to execute the command when the menu is open. The shortcut key is the key combination the user can press to run the command without opening the menu. Here’s a quick look at how to add access and shortcut keys to existing menu items:

    • Add an access key to a menu item Start the Menu Editor. Prefix the access key letter in the menu item caption with an ampersand (&).

    • Add a shortcut key to a menu command and Start the Menu Editor. Highlight the  command in the menu list box. Pick a key combination from the Shortcut drop-down list box.

    Creating Access and Shortcut Keys

    You can create access keys and shortcut keys either when you first create your menu commands or at a later time.

    The following illustration shows the menu commands associated with two menus,
    File and Clock. Each menu item has an access key ampersand character, and the
    Time and Date commands are assigned shortcut keys. See figure below.

    Figure 8.39 Menu Editor Window showing how to create shortcut keys

    8.5.5 Processing Menu Choices

    After you place menu items on the menu bar, they become objects in the program. To make the menu objects do meaningful work, you need to write event procedures for them. Typically, menu event procedures:

    • Contain program statements that display or process information on a form.

    • Modify one or more object properties.

    For example, the event procedure for a command named Time might use the Time keyword to display the current system time in a text box. Processing the selected command might require additional information (you might need to open a file on disk, for example). If so, you can display a dialog box to receive user input by using a common dialog box. You’ll learn this technique in the next section.

    Disabling a Menu Command

    In a typical Windows application, not all menu commands are available at the same time. In a typical Edit menu, for example, the Paste command is available only when there is data on the Clipboard. When a command is disabled, it appears in dimmed (gray) type on the menu bar. You can disable a menu item by:

    • Clearing the Enabled check box for that menu item in the Menu Editor.

    • Using program code to set the item’s Enable property to False. (When you’re ready to use the menu command again, set its Enable property to True.).

    Application activity 8.5

    Design a program which have five menus (Home,Insert,Page Layout, review and View) and sub_menu in home ( File, open and Edit) and the open File option display form1.

    You should be able to open the above form using shortcut(Ctrl+F).

    UNIT 7: OBJECT ORIENTED PROGRAMMING IN C++UNIT 9: VARIABLES, OPERATORS, EXPRESSIONS AND CONTROL STRUCTURES.