Title: Chapter 2: Designing Applications
1Chapter 2 Designing Applications
Programming with Microsoft Visual Basic 2005,
Third Edition
2Planning an Object-Oriented (OO) Application in
Visual Basic 2005 Lesson A Objectives
- Plan an OO application in Visual Basic 2005
- Complete a TOE (Task, Object, Event) chart
- Follow the Windows standards regarding the layout
and labeling of controls
2
Programming with Microsoft Visual Basic 2005,
Third Edition
3Solving the Problem Using a Procedure-Oriented
Approach
- Emphasis is on how to accomplish a task
- Flowchart
- Standardized symbols show problem-solving steps
- Pseudocode
- English phrases describing the required steps
- It is harder to write a complex application using
procedure oriented approach
3
Programming with Microsoft Visual Basic 2005,
Third Edition
4Solving the Problem Using an Object-Oriented
(OO) Approach
- Object-oriented programs
- Include objects that respond to events e.g.,
clicks - Examples of objects appearing on an interface
- Buttons, picture boxes, list boxes, text boxes,
labels - TOE (Task, Object, Event) chart
- Used to plan your object-oriented programs
- It is easier to write a complex application using
an object oriented approach
4
Programming with Microsoft Visual Basic 2005,
Third Edition
5Solving the Problem Using an Object-Oriented
(OO) Approach (continued)?
Figure 2-4 Order screen created by the OO
application
5
Programming with Microsoft Visual Basic 2005,
Third Edition
6Creating an OO Application
- Developing an application is like building a home
- Role of programmer analogous to that of builder
- Bugs problems that affect application functions
6
Programming with Microsoft Visual Basic 2005,
Third Edition
7Creating an OO Application (continued)?
Figure 2-6 Processes used by a builder and a
programmer
7
Programming with Microsoft Visual Basic 2005,
Third Edition
8Identifying the Tasks, Objects and Events
Figure 2-11 Completed TOE chart ordered by object
8
Programming with Microsoft Visual Basic 2005,
Third Edition
9Drawing a Sketch of the User Interface
Figure 2-12 Vertical arrangement of the
Skate-Away Sales interface
9
Programming with Microsoft Visual Basic 2005,
Third Edition
10Drawing a Sketch of the User Interface
(continued)?
Figure 2-13 Horizontal arrangement of the
Skate-Away Sales interface
10
Programming with Microsoft Visual Basic 2005,
Third Edition
11Building the User InterfaceLesson B Objectives
- Build the user interface using your TOE chart and
sketch - Follow the Windows standards regarding the use of
graphics, color, and fonts - Set a controls BorderStyle property
- Add a text box to a form
11
Programming with Microsoft Visual Basic 2005,
Third Edition
12Building the User InterfaceLesson B Objectives
(continued)?
- Lock the controls on the form
- Assign access keys to controls
- Use the TabIndex property
12
Programming with Microsoft Visual Basic 2005,
Third Edition
13Preparing to Create the User Interface less is
more
Figure 2-14 Partially completed interface for
the Skate-Away Sales application
13
Programming with Microsoft Visual Basic 2005,
Third Edition
14Adding a Text Box Control to the Form
Figure 2-16 Form showing the correct location of
the City text box
14
Programming with Microsoft Visual Basic 2005,
Third Edition
15Locking the Controls on a Form
- Lock controls after they are properly placed
- Purpose avoid inadvertently moving controls
- A locked control is identified by a small-lock
15
Programming with Microsoft Visual Basic 2005,
Third Edition
16Assigning Access Keys
- Access key
- Enables object to be selected using keyboard
- Key combination Alt key letter or number
- Each access key must be unique
- Assigning an access key
- Include an ampersand () in the controls caption
- Example CalculateOrder assigns C to button
16
Programming with Microsoft Visual Basic 2005,
Third Edition
17Setting the TabIndex Property
- Focus control state allowing a user to enter
input - Pressing Tab or access key shifts focus
- TabIndex property
- Determines when a control receive will receive
focus - Example label with TabIndex of 0 receives focus
first
17
Programming with Microsoft Visual Basic 2005,
Third Edition
18Coding, Testing, Debugging, and Documenting the
ApplicationLesson C Objectives
- Code an application using its TOE chart
- Plan an objects code using pseudocode or a
flowchart - Write an assignment statement
- Send the focus to a control while an application
is running
18
Programming with Microsoft Visual Basic 2005,
Third Edition
19Coding, Testing, Debugging, and Documenting the
ApplicationLesson C Objectives (continued)?
- Include internal documentation in the code
- Write arithmetic expressions
- Use the Val and Format functions
19
Programming with Microsoft Visual Basic 2005,
Third Edition
20Coding the Application
- Code
- Coding
- TOE charts show which objects and events to code
- Use pseudocode or flowchart to design procedure
20
Programming with Microsoft Visual Basic 2005,
Third Edition
21Using Pseudocode to Plan a Procedure
- Pseudocode instructions in English syntax
- Short phrases describe the steps of a procedure
- Travel directions are a type of pseudocode
21
Programming with Microsoft Visual Basic 2005,
Third Edition
22Using a Flowchart to Plan a Procedure
- Flowchart
- Uses standardized symbols to show program logic
- Pseudocode can be used within symbols
- Oval symbol start/stop symbol
- Rectangle symbol process symbol
- Parallelogram input/output symbol
- Flowlines connect symbols
22
Programming with Microsoft Visual Basic 2005,
Third Edition
23Coding the Clear Screen Button
Figure 2-28 Pseudocode for the xClearButtons
Click event procedure
23
Programming with Microsoft Visual Basic 2005,
Third Edition
24Assigning a Value to a Property During Run Time
- Assignment statement
- Instruction assigning a value to an object at
runtime - Syntax Me.object.propertyexpression
- Me refers to the current form (optional)?
- object and property are object and property names
- expression contains the value to be assigned
- Assignment operator () assigns value (right to
left)
24
Programming with Microsoft Visual Basic 2005,
Third Edition
25Assigning a Value to a Property During Run Time
(continued)?
Figure 2-32 Second assignment statement entered
in the procedure
25
Programming with Microsoft Visual Basic 2005,
Third Edition
26Using the Focus Method
- Method a predefined procedure
- Focus method
- Allows you to move the focus to a specified
control - Syntax Me.object.Focus()?
- Object is the name of the control that receives
focus
26
Programming with Microsoft Visual Basic 2005,
Third Edition
27Internally Documenting the Program Code
(continued)?
Figure 2-33 Completed Click event procedure for
the xClearButton
27
Programming with Microsoft Visual Basic 2005,
Third Edition
28Writing Arithmetic Expressions
Figure 2-35 Most commonly used arithmetic
operators and their order of precedence
28
Programming with Microsoft Visual Basic 2005,
Third Edition
29Coding the Calculate Order Button
Figure 2-39 Code entered in the xCalcButtons
Click event procedure numbers are treated as
strings
29
Programming with Microsoft Visual Basic 2005,
Third Edition
30The Val Function
- Function predefined procedure that returns a
value - Val function
- Converts a string to a number
- Returns the number
- Syntax Val(string) string will be treated as a
number - Val corrects assignments in xCalcButtons
procedure
30
Programming with Microsoft Visual Basic 2005,
Third Edition
31The Val Function (continued)?
Figure 2-42 Val function entered in the
xCalcButtons Click event procedure
31
Programming with Microsoft Visual Basic 2005,
Third Edition
32Using the Format Function to Format Numeric Output
- Format function improves numbers display
- Syntax Format(expression, style)?
- Expression specifies number, date, time, or
string - Style predefined or user defined format style
- Currency example of a format style
- Displays number with a dollar sign and two
decimal places
32
Programming with Microsoft Visual Basic 2005,
Third Edition