THEORY AND PROBLEMS OF PROGRAMMING WITH VISUAL BASIC

THEORY AND PROBLEMS OF PROGRAMMING WITH VISUAL BASIC ------------Dr. Samih Mohammed Mostafa Assistant Professor South Valley University

Introducing Visual Basic Chapter 1 WHAT IS VISUAL BASIC? Visual Basic is an object-oriented programming development. Two major components: • controls • program commands

Introducing Visual Basic Chapter 1 The overall approach to Visual Basic programming is twofold: 1. Create a user interface that is appropriate to the particular application at hand. 2. Add a group of Basic instructions to carry out the actions associated with each of the controls.

Introducing Visual Basic Chapter 1 • Visual Basic is based upon an event-driven paradigm. • The program’s response to an action taken by the user is referred to as an event. • The user initiates the event, but it is the program’s response that actually defines the event. • The group of Basic commands that brings about this response is called an event procedure.

Introducing Visual Basic Chapter 1 • Understand the meaning of each of the following terms: • Forms: a window is called a form. Each form includes a title bar at the top. a menu bar, a status bar, one or more toolbars, slide bars, etc

Introducing Visual Basic Fig. 1. 1 A form containing three controls Chapter 1

Introducing Visual Basic • Chapter 1 Controls: The icons with which the user interacts are called controls. • Objects: Forms and controls are referred to collectively as objects. Most objects are associated with events. • Properties: Objects include properties that generally define their appearance or behavior.

Introducing Visual Basic Chapter 1 • Methods: Some objects also include special program statements called methods. A method brings about some predefined action affecting the associated object

THE VISUAL BASIC PROGRAM DEVELOPMENT PROCESS • Chapter 1 The process of writing a Visual Basic program consists of several steps. They are: 1 - Decide what the program is supposed to do. 2 - Create a user interface: - Draw the controls within their respective forms. - Define the properties of each control. 3 - Write the Visual Basic instructions. 4 - Run the program. 5 - Repeat one or more steps if the results are incorrect.

THE VISUAL BASIC PROGRAM DEVELOPMENT PROCESS • Chapter 1 The process of writing a Visual Basic program consists of several steps. They are: 1 - Decide what the program is supposed to do. 2 - Create a user interface: - Draw the controls within their respective forms. - Define the properties of each control. 3 - Write the Visual Basic instructions. 4 - Run the program. 5 - Repeat one or more steps if the results are incorrect.

REQUIRED COMPUTER SKILLS Chapter 1 • You should have some proficiency in all of the following: 1. Familiarity with one of the Microsoft Windows operating systems 2. Managing files within Windows 3. Installing new applications

LOGICAL PROGRAM ORGANIZATION • Chapter 1 Virtually all nontrivial computer programs involve three major tasks. They are: 1. Entering input data (supplying information to be processed). 2. Computing the desired results (processing the input data). 3. Displaying the results (displaying the results of the computation.

VISUAL BASIC PROGRAM COMPONENTS Chapter 1 • a program is referred to as a project: • Every Visual Basic project consists of at least two separate files: - a project file (whose extension is. vbp), and - a form file (with extension. frm).

THE VISUAL BASIC ENVIRONMENT Chapter 1 for a new project by selecting New/Standard. EXE, or by selecting New Project from the File menu

THE VISUAL BASIC ENVIRONMENT Fig. 1. 3 The Visual Basic new project environment Chapter 1

VISUAL BASIC PROGRAM COMPONENTS • Chapter 1 TITLE BAR: The top line is called the Title Bar. It includes the project name. • MENU BAR: The second line is called the Menu Bar. Selecting one of the choices (File, Edit, View, Project, Format, . . . Help) • TOOLBAR: The icons on this line duplicate several of the more commonly used menu selections that are available via the drop-down menus accessed from the Menu Bar

VISUAL BASIC PROGRAM COMPONENTS • Chapter 1 FORM DESIGN AND PROJECT CONTAINER WINDOWS: The Form Design Window is where the user interface is actually designed. • TOOLBOX: The Toolbox contains icons that represent commonly used controls. • PROPERTIES WINDOW: The Properties Window allows you to assign or change the properties associated with a particular object • PROJECT WINDOW: displays a hierarchical list of the files associated with a given project

VISUAL BASIC PROGRAM COMPONENTS • Chapter 1 CODE EDITOR WINDOW: displaying the Visual Basic code associated with the currently active form. Fig. 1. 4 The Code Editor Window containing two event procedures

VISUAL BASIC PROGRAM COMPONENTS • Chapter 1 FORM LAYOUT WINDOW: allows you to specify the screen location of the forms within a project. • IMMEDIATE WINDOW: is very useful when debugging a project. • REPOSITIONING, RESIZING, DELETING, ADDING, AND DOCKING WINDOWS: Docked windows are always aligned alongside their neighbors, and they are always visible.

VISUAL BASIC PROGRAM COMPONENTS Chapter 1 OPENING AN EXISTING VISUAL BASIC PROJECT: an existing project can be accessed by locating the project name listed under the Existing or the Recent tab within the New Project window or by locating the project via File/Open Project.

VISUAL BASIC PROGRAM COMPONENTS Chapter 1 • SAVING A VISUAL BASIC PROJECT: choose Save Project As from the File menu. You will be prompted separately for a form name (i. e. , the name of the. frm file) and a project name (the. vbp file). Usually, the same name is given to both files.

VISUAL BASIC PROGRAM COMPONENTS Chapter 1 RUNNING A VISUAL BASIC PROJECT: To execute a Visual Basic project, simply click on the Start button in the Toolbar (see Fig. 1. 6), or select Start from the Run menu. • The execution can be temporarily suspended by clicking on the Break button, or by selecting Break from the Run menu. The execution of a paused project can then be resumed by clicking on the Run button, or by selecting Continue from the Run menu. To end the execution, simply click on the End button, or select End from the Run menu.

VISUAL BASIC PROGRAM COMPONENTS Chapter 1 GETTING HELP: To access the help feature, press function key F 1 or select Contents, Index or Search from the Help menu.

Example Chapter 1 A SAMPLE VISUAL BASIC PROJECT: EXAMPLE 1. 1 AREA OF A CIRCLE: calculates the area of a circle. The user enters a value for the radius, and then clicks on the Go button. The corresponding area will then be displayed, as illustrated

Example Chapter 1 We begin by opening Visual Basic and selecting Standard EXE from the New tab in the New Project menu (see Fig. 1. 2). This causes a blank Form Design Window to be displayed, as shown in Fig. 1. 9 (see also Fig. 1. 3).

Example Chapter 1 We then place the necessary controls in the Form Design Window. In particular, we place two labels, two text boxes, two command buttons, and a geometric shape on the form. Note that the controls are automatically called Label 1, Label 2, Text 1, Text 2, Command 1, and Command 2, and the Form Design Window is called Form 1. The geometric shape has no default name. Each control can be selected two different ways: - Click and then drag the mouse - Double-click

Example Chapter 1 Defining the Interface Control Properties. To view the properties, simply activate the control by clicking on it

Example Chapter 1

Example Chapter 1 The last step is to write the Visual Basic commands that comprise the event procedures only the command buttons, labeled Go and End

Example Chapter 1 To define the event procedure associated with the Go button, double-click on the button. This will cause the Code Editor Window to be displayed the first and last line of each event procedure (e. g. , Private Sub Command 1_Click() and End Sub) are provided automatically, separated by a blank line.

Example Chapter 1 The first line is a variable declaration, stating that R and A are single-precision, real variables. The remaining three lines are assignment statements
- Slides: 31