T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 8 Dental Payment Application Introducing CheckBox es and Message Dialogs.

Slides:



Advertisements
Similar presentations
Microsoft Visual Basic: Reloaded Chapter Five More on the Selection Structure.
Advertisements

© by Pearson Education, Inc. All Rights Reserved. continued …
VB Express 2008 Overview Chapters 5-8. Summary So Far We have talked about the basics of VB. How to add controls on the form? Naming convention of controls.
Control Structures: Part 2. Introduction Essentials of Counter-Controlled Repetition For / Next Repetition Structure Examples Using the For / Next Structure.
Control Structures: Getting Started Sequence and Selection also arithmetic operators, data types, logical operators.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 03.
Chapter 7 – Control Structures A payroll company calculates the gross earnings per week of employees. Employees’ weekly salaries are based on the number.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 9 Car Payment Calculator Application Introducing the Do While...Loop and Do Until...Loop.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Flag Quiz Application Introducing One-Dimensional Arrays and ComboBox es.
Chapter 4: The Selection Structure
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Interest Calculator Application Introducing the For...Next Repetition Statements.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Typing Application Introducing Keyboard Events, Menus, Dialogs and the Dictionary.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 2 Welcome Application Introducing the Visual Basic 2008 Express Edition IDE.
Chapter 3 Making Decisions
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Enhancing the Wage Calculator Application Introducing Function Procedures and.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 7.1 Test-Driving the Wage Calculator Application.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 5 Decision Making.
Dale Roberts Program Control using Java - Boolean Expressions Dale Roberts, Lecturer Computer Science, IUPUI Department of.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 5 – Dental Payment Application: Introducing.
 2002 Prentice Hall. All rights reserved. 1 Chapter 5 – Control Structures: Part 2 Outline 5.1Introduction 5.2 Essentials of Counter-Controlled Repetition.
Problem Solving and Control Statements. Using Exit to Terminate Repetition Statements There are many forms of the Exit statement, designed to terminate.
 2009 Pearson Education, Inc. All rights reserved Control Statements: Part 2.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved CheckWriter Application Introducing Graphics and Printing.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 3 Welcome Application Introduction to Visual Programming.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 5 Completing the Inventory Application Introducing Programming.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 17 – Flag Quiz Application Introducing One-Dimensional.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Security Panel Application Introducing the Select Case Multiple-Selection Statement.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Class Average Application Introducing the Do...Loop While and Do...Loop Until.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Microwave Oven Application Building Your Own Classes and Objects.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 25.1 Test-Driving the ATM Application 25.2.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #5 Control Statements: Part 2.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 18 – Student Grades Application Introducing.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 5.1 Test-Driving the Inventory Application.
Sections © Copyright by Pearson Education, Inc. All Rights Reserved.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Craps Game Application Introducing Random-Number Generation and Enum.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 4 Designing the Inventory Application Introducing TextBox es and Button s.
5.1 Introduction Problem Solving –Requires understanding of: Building blocks Program-construction principles BZUPAGES.COM.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Address Book Application Introducing Database Programming.
 2002 Prentice Hall. All rights reserved. 1 Chapter 5 – Control Structures: Part 2 Outline 5.1Introduction 5.2 Essentials of Counter-Controlled Repetition.
 2006 Pearson Education, Inc. All rights reserved Control Statements: Part 2.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 7 Wage Calculator Application Introducing Algorithms, Pseudocode and Program Control.
Chapter 4 Select … Case Multiple-Selection Statement & Logical Operators 1 © by Pearson Education, Inc. All Rights Reserved. -Edited By Maysoon.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
 2007 Pearson Education, Inc. All rights reserved Control Statements: Part2.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 7.1 Test-Driving the Dental Payment Application.
 You won’t write a single line of program code.  Instead, you’ll use visual programming techniques.  Visual Studio processes your actions (such as mouse.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Enhanced Car Payment Calculator Application Introducing Exception Handling.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.-Edited By Maysoon Al-Duwais1.
Problem Solving and Control Statements: Part 2
Chapter 5- Control Structures: Part 2
Control Statements: Part 2
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Chapter 5 – Control Structures: Part 2
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Chapter 6 Control Statements: Part 2
Problem Solving and Control Statements
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Presentation transcript:

T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 8 Dental Payment Application Introducing CheckBox es and Message Dialogs

 2009 Pearson Education, Inc. All rights reserved. 2 Outline 8.1 Test-Driving the Dental Payment Application 8.2 Designing the Dental Payment Application 8.3 Using CheckBox es 8.4 Using a Dialog to Display a Message 8.5 Logical Operators 8.6 Designer-Generated Code

 2009 Pearson Education, Inc. All rights reserved. 3 In this tutorial you will learn: ■Use CheckBox es to allow users to select options. ■Use dialogs to display messages. ■Use logical operators to form more powerful conditions. Objectives

Application Requirements  2009 Pearson Education, Inc. All rights reserved Test-Driving the Dental Payment Application A dentist’s office administrator wishes to create an application that employees can use to bill patients. The application must allow users to enter the patient’s name and specify which services were performed during the visit. The application will then calculate the total charges. If a user attempts to calculate a bill before any services are specified, or before the patient’s name is entered, an error message informing the user that necessary input is missing will be displayed.

 2009 Pearson Education, Inc. All rights reserved. 5 ■A CheckBox is a small square that either is blank or contains a check mark ( ). ■Open the Dental Payment application (Fig. 8.1). CheckBox controls (unchecked) Figure 8.1 | Running the completed Dental Payment application. Test-Driving the Dental Payment Application

 2009 Pearson Education, Inc. All rights reserved. 6 ■Leave the Patient name: field blank, and deselect any CheckBox es that you’ve selected before clicking the Calculate Button. ■An error message appears (Fig. 8.2); close it by clicking the OK button. Figure 8.2 | Message dialog appears when no name is entered and/or no CheckBox es are selected. Test-Driving the Dental Payment Application (Cont.)

 2009 Pearson Education, Inc. All rights reserved. 7 ■Run the application and enter information (Fig. 8.3). Figure 8.3 | Dental Payment application with input entered. Test-Driving the Dental Payment Application (Cont.) CheckBox controls (checked)

 2009 Pearson Education, Inc. All rights reserved. 8 ■Uncheck the Cavity Filling CheckBox (Fig. 8.4). Figure 8.4 | Dental Payment application with input changed. Test-Driving the Dental Payment Application (Cont.) CheckBox controls (checked)

 2009 Pearson Education, Inc. All rights reserved. 9 ■Click the Calculate button to calculate the total (Fig. 8.5). Figure 8.5 | Dental Payment application with total calculated. Test-Driving the Dental Payment Application (Cont.) CheckBox controls (checked)

 2009 Pearson Education, Inc. All rights reserved. 10 When the user clicks the Calculate Button Clear previous output If user has not entered a patient name or has not selected any CheckBoxes Display message in dialog Else Initialize the total to zero If “Cleaning” CheckBox is selected Add cost of a cleaning to the total If “Cavity Filling” CheckBox is selected Add cost of receiving a cavity filling to the total If “X-Ray” CheckBox is selected Add cost of receiving an x-ray to the total Format total to be displayed as currency Display total 8.2 Designing the Dental Payment Application

 2007 Pearson Education, Inc. All rights reserved. 11 Action/Control/Event (ACE) Table for the Dental Payment Application Figure 8.6 | ACE table for Dental Payment application. (Part 1 of 2.)

 2007 Pearson Education, Inc. All rights reserved. 12 Action/Control/Event (ACE) Table for the Dental Payment Application (Cont.) Figure 8.6 | ACE table for Dental Payment application. (Part 2 of 2.)

 2009 Pearson Education, Inc. All rights reserved. 13 ■A CheckBox is known as a state button because it can be in the on/off [true/false] state. ■The text that appears alongside a CheckBox is called the CheckBox label. ■If the CheckBox is checked, the Checked property contains the Boolean value True ; otherwise, it contains False. 8.3 Using CheckBox es

 2009 Pearson Education, Inc. All rights reserved. 14 GUI Design Tip A CheckBox ’s label should be descriptive and as short as possible. When a CheckBox ’s label contains more than one word, use book-title capitalization.

 2009 Pearson Education, Inc. All rights reserved. 15 ■Add a CheckBox to the Form by double clicking the icon in the Toolbox. Repeat this process until three CheckBox es have been added to the Form. ■Customizing the CheckBox es. –First, set the AutoSize property to False and change the Size to 122, 24 for all three CheckBox es. –Name the first CheckBox cleanCheckBox, set its Location to 22, 113 and set its Text to Cleaning. –Name the second CheckBox cavityCheckBox, set its Location to 22, 160 and set its Text to Cavity Filling. –Name the final CheckBox xrayCheckBox, set its Location to 22, 207 and set its Text to X-Ray. Adding CheckBox es to the Form

 2009 Pearson Education, Inc. All rights reserved. 16 GUI Design Tip Align groups of CheckBox es either horizontally or vertically.

 2009 Pearson Education, Inc. All rights reserved. 17 ■Double click the Calculate Button on the Form to create an event handler (Fig. 8.7). Figure 8.7 | Using the Checked property. Adding the Calculate Button ’s Event Handler Add this highlighted code

 2009 Pearson Education, Inc. All rights reserved. 18 ■Select the Cleaning CheckBox, and click the Calculate Button. The Total: field now displays $35.00 (Fig. 8.8). Figure 8.8 | Application running without input. Adding the Calculate Button ’s Event Handler (Cont.) Application calculates a bill of $0.00 when no CheckBoxes are checked

 2009 Pearson Education, Inc. All rights reserved. 19 ■This dialog (Fig. 8.9) contains: –a title bar –a close box –a message –an OK button –an icon indicating the tone of the message 8.4 Using a Dialog to Display a Message OK Button allows the user to close the dialog Dialog sized to accommodate contents Close box Title bar Icon indicates the tone of the message Figure 8.9 | Dialog displayed by the application.

 2009 Pearson Education, Inc. All rights reserved. 20 GUI Design Tip Text displayed in a dialog should be descriptive and as short as possible.

 2009 Pearson Education, Inc. All rights reserved. 21 ■The message should display only if the user does not enter the patient’s name. ■If no data has been entered, the expression nameTextBox.Text = "" evaluates to True (Fig. 8.10). Add this highlighted code Figure 8.10 | Adding an If...Then statement to the calculateButton Click event handler to display a message dialog. Displaying a Message Dialog Using MessageBox.Show

 2009 Pearson Education, Inc. All rights reserved. 22 ■ MessageBox.Show has four arguments separated by commas (Fig. 8.11). –The first argument specifies the dialog text. –The second argument specifies the title bar text. –The third argument indicates which Button to display. –The fourth argument indicates which icon appears. Displaying a Message Dialog Using MessageBox.Show (Cont.) Add this highlighted code Figure 8.11 | Message dialog code that displays a message to users. Change End If to Else

 2009 Pearson Education, Inc. All rights reserved. 23 ■Insert the keywords End If to close the If...Then...Else... statement (Fig. 8.12). Add this highlighted code Figure 8.12 | Ending the If...Then...Else statement. Displaying a Message Dialog Using MessageBox.Show (Cont.)

 2009 Pearson Education, Inc. All rights reserved. 24 ■Figure 8.13 displays the completed event handler. Figure 8.13 | Completed calculateButton_Click event handler. Displaying a Message Dialog Using MessageBox.Show (Cont.)

 2009 Pearson Education, Inc. All rights reserved. 25 ■Run the application (Fig. 8.14). Figure 8.14 | Total calculated without any CheckBox es selected. Displaying a Message Dialog Using MessageBox.Show (Cont.) Application calculates a bill of $0.00 when a name is entered and no CheckBoxes are checked User must now enter a name

 2009 Pearson Education, Inc. All rights reserved. 26 ■Figure 8.15 lists the available MessageBoxButtons constants. Figure 8.15 | Message dialog MessageBoxButtons constants. 8.4 Using a Dialog to Display a Message (Cont.)

 2009 Pearson Education, Inc. All rights reserved. 27 ■Some of the available icon constants are shown in Fig Figure 8.16 | Some message dialog MessageBoxIcon constants. 8.4 Using a Dialog to Display a Message (Cont.)

 2009 Pearson Education, Inc. All rights reserved. 28 ■Simple conditions such as count 1000, and number <> value use only one condition with one of the operators >, =,. ■Visual Basic provides logical operators that can be used to form complex conditions. ■The logical operators are: – And – AndAlso – Or – OrElse – Xor – Not 8.5 Logical Operators

 2009 Pearson Education, Inc. All rights reserved. 29 Error-Prevention Tip Always write the simplest condition possible by limiting the number of logical operators used. Conditions with many logical operators can be hard to read and can introduce subtle bugs into your applications.

 2009 Pearson Education, Inc. All rights reserved. 30 ■ Using AndAlso –To ensure that two conditions are both true in an application, use the logical AndAlso operator as follows: If genderTextBox.Text = "Female" AndAlso age >= 65 Then seniorFemales += 1 End If –Figure 8.17 illustrates the outcome of using the AndAlso operator with two expressions. Such tables are called truth tables. 8.5 Logical Operators (Cont.) Figure 8.17 | Truth table for the AndAlso operator.

 2009 Pearson Education, Inc. All rights reserved. 31 ■Using OrElse –To ensure that either or both of two conditions are true, use the OrElse operator. If (semesterAverage >= 90 ) OrElse (finalExam >= 90) Then MessageBox.Show( "Student grade is A", "Student Grade", _ MessageBoxButtons.OK, MessageBoxIcon.Information ) End If –Figure 8.18 provides a truth table for the OrElse operator. –Note that the AndAlso operator has a higher precedence. 8.5 Logical Operators (Cont.) Figure 8.18 | Truth table for the OrElse operator.

 2009 Pearson Education, Inc. All rights reserved. 32 ■Short-Circuit Evaluation –The following expression stops immediately if genderTextBox.Text is not equal to "Female“ (genderTextBox.Text = "Female" ) AndAlso (age >= 65 ) –The evaluation of the second expression is irrelevant; once the first expression is known to be false, the whole expression must be false. –This way of evaluating logical expressions, called short-circuit evaluation, requires fewer operations and takes less time. ■Visual Basic also provides the And and Or operators, which do not short-circuit. 8.5 Logical Operators (Cont.)

 2009 Pearson Education, Inc. All rights reserved. 33 ■Using Xor –The logical exclusive OR ( Xor ) operator is True if and only if one of its operands results in a True value and the other results in a False value. –If both operands are True or both are False, the entire condition is false. –Figure 8.19 provides a truth table for the Xor operator. 8.5 Logical Operators (Cont.) Figure 8.19 | Truth table for the logical exclusive OR ( Xor ) operator.

 2009 Pearson Education, Inc. All rights reserved. 34 ■Using Not –Visual Basic ’ s Not operator enables you to “ reverse ” the meaning of a condition. If Not (grade = value) Then displayLabel.Text = "They are not equal!“ End If –The parentheses around the condition grade = value improve the readability of the condition. –Figure 8.20 provides a truth table for the Not operator. 8.5 Logical Operators (Cont.) Figure 8.20 | Truth table for the Not operator (logical negation).

 2009 Pearson Education, Inc. All rights reserved. 35 ■Note the use of OrElse and AndAlso (Fig. 8.21). ■Note that users must enter a name and select at least one CheckBox before they click the Calculate Button, or the dialog will be displayed. Figure 8.21 | Using the AndAlso and OrElse logical operators. Using Logical Operators in Complex Expressions Add the highlighted code

 2009 Pearson Education, Inc. All rights reserved. 36 ■Figure 8.22 presents the source code for the application. Using logical operators and the Checked property of a CheckBox Outline (1 of 3 )

 2009 Pearson Education, Inc. All rights reserved. 37 Determine whether cleanCheckBox is checked Outline Displaying a MessageBox

 2009 Pearson Education, Inc. All rights reserved. 38 Determine whether cavityCheckBox is checked Determine whether xrayCheckBox is checked Outline (3 of 3 )

 2009 Pearson Education, Inc. All rights reserved. 39 ■Like the variables you’ve declared, GUI controls also must be declared before they are used. ■When you work in Design view, Visual Basic automatically declares the controls for you. ■To improve the readability of your application code, Visual Basic “hides” the GUI declarations and other GUI code it generates in a separate file. ■Click the Show All Files button in the Solution Explorer, then click the plus ( + ) sign next to DentalPayment.vb to expand its node. 8.6 Designer-Generated Code

 2009 Pearson Education, Inc. All rights reserved. 40 ■Figure 8.23 shows some of the declarations that the IDE generated. Figure 8.23 | GUI declarations for the controls in the Dental Payment application. 8.6 Designer-Generated Code (Cont.)

 2009 Pearson Education, Inc. All rights reserved. 41 ■Figure 8.24 shows some of the statements that the IDE generated when you set the properties of the CheckBox es. Figure 8.24 | Statements that configure the CheckBox properties. 8.6 Designer-Generated Code (Cont.)