Upload
hollie-charles
View
242
Download
5
Embed Size (px)
Citation preview
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
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
Clearly Visual Basic: Programming with Visual Basic 2008 4
5Clearly Visual Basic: Programming with Visual Basic 2008
6Clearly Visual Basic: Programming with Visual Basic 2008
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
Clearly Visual Basic: Programming with Visual Basic 2008 8
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
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
Clearly Visual Basic: Programming with Visual Basic 2008 11
Clearly Visual Basic: Programming with Visual Basic 2008 12
Quick Access Keys- Driven by the ALT KEY
13Clearly Visual Basic: Programming with Visual Basic 2008
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
Clearly Visual Basic: Programming with Visual Basic 2008 15
Tab Order- View- Tab Order
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
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
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
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 93 #3 – Tip Calculator Interface
Note: We are just doing Interfaces, Tab Orders, and Access Keys, NOT the programming- Except the Exit Button
Page 94 #4 Property Tax Solution
Clearly Visual Basic: Programming with Visual Basic 2008 21
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 95 #5 Sales Project
Clearly Visual Basic: Programming with Visual Basic 2008 23
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
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
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