Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 5 Do It Yourself Designing.

26
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 5 Do It Yourself Designing

Transcript of Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 5 Do It Yourself Designing.

Page 1: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 5 Do It Yourself Designing.

Clearly Visual Basic: Programming with Visual Basic 2008

Chapter 5 Do It Yourself Designing

Page 2: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 5 Do It Yourself Designing.

Objectives

• Use a text box to get user input

• Perform an action with a button control

• Code a control’s Click event procedure

• Stop an application using the Me.Close() instruction

Clearly Visual Basic: Programming with Visual Basic 2008 2

Page 3: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 5 Do It Yourself Designing.

Delegating the Work

• Figure 5-1 – Shows Addison Smith problem’s output, input, and

algorithm

• When designing interface for a problem– Examine each step in the problem’s algorithm, along

with its output and input items

• Assign meaningful names to each of the controls listed in Figure 5-2

• Camel case – Uppercase letters appear as “humps” in the name

Clearly Visual Basic: Programming with Visual Basic 2008 3

Page 4: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 5 Do It Yourself Designing.

Clearly Visual Basic: Programming with Visual Basic 2008 4

Page 5: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 5 Do It Yourself Designing.

5Clearly Visual Basic: Programming with Visual Basic 2008

Page 6: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 5 Do It Yourself Designing.

6Clearly Visual Basic: Programming with Visual Basic 2008

Page 7: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 5 Do It Yourself Designing.

Clearly Visual Basic: Programming with Visual Basic 2008 7

Mini Quiz1.It is customary to show the results of a calculation as a ____.2.Using Hungarian Notation, which of the following is a good name for the city? cityTextBox TextBoxCity txtCity TxtCity3.The three-character ID for a button control name is ______.

Page 78- Commission Calculator ProgramCreate a new application program called Commission Calculator ProjectChange font property to Sego UI, 9pt and StartPosition to CenterScreenChange the forms Text Property to Commission CalculatorChange the forms Name to: frmMain

Page 8: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 5 Do It Yourself Designing.

Clearly Visual Basic: Programming with Visual Basic 2008 8

Page 9: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 5 Do It Yourself Designing.

Delegating the Work (continued)

• Sentence capitalization– Capitalize only first letter in each word and in any

words that are customarily capitalized– Example: identifying labels

• Book title capitalization– Capitalize first letter in each word, except for articles,

conjunctions, and prepositions– Example: button captions

Clearly Visual Basic: Programming with Visual Basic 2008 9

Page 10: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 5 Do It Yourself Designing.

Making the Interface More User-Friendly

• Access key– Allows user to select a menu using the Alt key in

combination with a letter or number– Not case sensitive– Should be assigned to each control (in the interface)

that can accept user input– Allows user to work with interface even when mouse

becomes inoperative

Clearly Visual Basic: Programming with Visual Basic 2008 10

Page 11: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 5 Do It Yourself Designing.

Clearly Visual Basic: Programming with Visual Basic 2008 11

Page 12: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 5 Do It Yourself Designing.

Clearly Visual Basic: Programming with Visual Basic 2008 12

Quick Access Keys- Driven by the ALT KEY

Page 13: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 5 Do It Yourself Designing.

13Clearly Visual Basic: Programming with Visual Basic 2008

Page 14: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 5 Do It Yourself Designing.

Making the Interface More User-Friendly (continued)

• Tab order– Determined by number stored in each control’s

TabIndex property

• When interface is first created– TabIndex values reflect the order in which each

control was added to the form

Clearly Visual Basic: Programming with Visual Basic 2008 14

Page 15: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 5 Do It Yourself Designing.

Clearly Visual Basic: Programming with Visual Basic 2008 15

Tab Order- View- Tab Order

Page 16: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 5 Do It Yourself Designing.

Do What I Tell You To Do

• Code– Visual Basic instructions

• Event procedure– Tells an object how to respond to an event

• Code Editor window– Used to enter an event procedure’s code

Clearly Visual Basic: Programming with Visual Basic 2008 16

Page 17: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 5 Do It Yourself Designing.

The Me.Close() Instruction

• Tells the computer to close the current form

• Method – A predefined procedure that you can call (or invoke)

when needed

• Good programming practice: test a procedure after you have coded it

Clearly Visual Basic: Programming with Visual Basic 2008 17

Page 18: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 5 Do It Yourself Designing.

Mini Quiz 2

• If a text box’s Tab Index is set to 7, it’s indentifying label should be set to: _______

• If a text box’s access key is the letter t, you can move the focus to the text box by pressing _____

• The first line in a procedure (when you double click on a button) is the: ______ procedure header

Clearly Visual Basic: Programming with Visual Basic 2008 18

Page 19: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 5 Do It Yourself Designing.

Review Questions• To give the user control, assign the task to a:

Button Label Picture Box Text Box

• Which of the following designates Z as an access key?*Zip Code ^Zip Code &Zip Code #Zip Code

• The computer processes a button’s click when the user:Clicks the button Uses button access code Tabs to the Button All of the These

• Which of the following appears in the header and associates the procedure with the btnSave control’s Click Event: The answer is: Handles.btnSave.Click

• Which of the following tells the computer to stop an application: The answer is Me.Close ()

Clearly Visual Basic: Programming with Visual Basic 2008 19

Page 20: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 5 Do It Yourself Designing.

Page 93 #3 – Tip Calculator Interface

Note: We are just doing Interfaces, Tab Orders, and Access Keys, NOT the programming- Except the Exit Button

Page 21: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 5 Do It Yourself Designing.

Page 94 #4 Property Tax Solution

Clearly Visual Basic: Programming with Visual Basic 2008 21

Page 22: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 5 Do It Yourself Designing.

Property Tax Solution Algorithm

Output: annual property tax

Input: Assessed Value Property Tax Rate

Algorithm:1.Enter assessed value and property tax rate2.Calculate annual property tax by dividing accessed value by 100, and then multiplying the quotient by the property tax rate3.Display the annual property tax

Page 23: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 5 Do It Yourself Designing.

Page 95 #5 Sales Project

Clearly Visual Basic: Programming with Visual Basic 2008 23

Page 24: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 5 Do It Yourself Designing.

Sales Solution AlgorithmOutput: Total Sales, North Percent, South Percent, East Percent, West PercentInput: North region sales, South sales, East sales, West sales

Algorithm: 1.Enter North sales, South Sales, East Sales & West Sales2.Calculate Total Sales by added up all the regions sales3.Calculate North’s percent by dividing North’s Sales by Total Sales4.Calculate South’s percent by dividing South’s Sales by Total Sales5.Calculate East’s percent by dividing East’s Sales by Total Sales6.Calculate West’s percent by dividing West’s Sales by Total Sales7.Display Total Sales, North’s Percent, South’s percent, East’s Percent and West’s Percent

Page 25: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 5 Do It Yourself Designing.

Summary

• A problem’s input, output, and algorithm – Used when designing solution’s interface

• Text boxes provide area for user to enter data

• Buttons are used to perform action when clicked

• Output items typically appear in label controls

• Object names in Hungarian notation – Begin with an ID that identifies the object’s type

Clearly Visual Basic: Programming with Visual Basic 2008 25

Page 26: Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 5 Do It Yourself Designing.

Summary (continued)

• To prevent a label from changing its size while application is running:– Change its AutoSize property to False

• A label’s BorderStyle property – Determines whether the label has a border

• An interface’s tab order – Determined by number stored in each control’s

TabIndex Property

• The Me.Close() instruction – Used to end an application

Clearly Visual Basic: Programming with Visual Basic 2008 26