1 Chapter 4 – Decisions 4.1 Relational and Logical Operators (see other set of slides) 4.2 If...
-
Upload
patrick-morgan -
Category
Documents
-
view
219 -
download
2
description
Transcript of 1 Chapter 4 – Decisions 4.1 Relational and Logical Operators (see other set of slides) 4.2 If...
![Page 1: 1 Chapter 4 – Decisions 4.1 Relational and Logical Operators (see other set of slides) 4.2 If Blocks (see other set of slides) 4.3 Select Case Blocks (see.](https://reader036.fdocuments.net/reader036/viewer/2022070605/5a4d1adb7f8b9ab059974e8b/html5/thumbnails/1.jpg)
1
Chapter 4 – Decisions4.1 Relational and Logical Operators (see
other set of slides)4.2 If Blocks (see other set of slides)4.3 Select Case Blocks (see other set of
slides)4.4 Input via User Selection
![Page 2: 1 Chapter 4 – Decisions 4.1 Relational and Logical Operators (see other set of slides) 4.2 If Blocks (see other set of slides) 4.3 Select Case Blocks (see.](https://reader036.fdocuments.net/reader036/viewer/2022070605/5a4d1adb7f8b9ab059974e8b/html5/thumbnails/2.jpg)
4.4 Input via User Selection• Using a List Box for Input• Using Radio Buttons for Input• Using Check Boxes for Input• Events Raised by Selections
2
![Page 3: 1 Chapter 4 – Decisions 4.1 Relational and Logical Operators (see other set of slides) 4.2 If Blocks (see other set of slides) 4.3 Select Case Blocks (see.](https://reader036.fdocuments.net/reader036/viewer/2022070605/5a4d1adb7f8b9ab059974e8b/html5/thumbnails/3.jpg)
The Three Types of Controls Used for Selection
3
list box
radio buttons check
boxes
Which would you use for:
Age? Ethnicity?
![Page 4: 1 Chapter 4 – Decisions 4.1 Relational and Logical Operators (see other set of slides) 4.2 If Blocks (see other set of slides) 4.3 Select Case Blocks (see.](https://reader036.fdocuments.net/reader036/viewer/2022070605/5a4d1adb7f8b9ab059974e8b/html5/thumbnails/4.jpg)
Fill a List Box at Design Time via its String Collection Editor
4
Tasks button
click here to invoke string collection editor
![Page 5: 1 Chapter 4 – Decisions 4.1 Relational and Logical Operators (see other set of slides) 4.2 If Blocks (see other set of slides) 4.3 Select Case Blocks (see.](https://reader036.fdocuments.net/reader036/viewer/2022070605/5a4d1adb7f8b9ab059974e8b/html5/thumbnails/5.jpg)
String Collection Editor
5
Fill by direct typing or by copying and pasting from a text editor or a spreadsheet.
![Page 6: 1 Chapter 4 – Decisions 4.1 Relational and Logical Operators (see other set of slides) 4.2 If Blocks (see other set of slides) 4.3 Select Case Blocks (see.](https://reader036.fdocuments.net/reader036/viewer/2022070605/5a4d1adb7f8b9ab059974e8b/html5/thumbnails/6.jpg)
List Box at Run Time
6
lstMonths
selected item
The value of lstMonths.Text is the string consisting of the selected item.
![Page 7: 1 Chapter 4 – Decisions 4.1 Relational and Logical Operators (see other set of slides) 4.2 If Blocks (see other set of slides) 4.3 Select Case Blocks (see.](https://reader036.fdocuments.net/reader036/viewer/2022070605/5a4d1adb7f8b9ab059974e8b/html5/thumbnails/7.jpg)
Example 4.4.1– Form Designer
Items property
Collections editor
![Page 8: 1 Chapter 4 – Decisions 4.1 Relational and Logical Operators (see other set of slides) 4.2 If Blocks (see other set of slides) 4.3 Select Case Blocks (see.](https://reader036.fdocuments.net/reader036/viewer/2022070605/5a4d1adb7f8b9ab059974e8b/html5/thumbnails/8.jpg)
Code
8
Selection by user
![Page 9: 1 Chapter 4 – Decisions 4.1 Relational and Logical Operators (see other set of slides) 4.2 If Blocks (see other set of slides) 4.3 Select Case Blocks (see.](https://reader036.fdocuments.net/reader036/viewer/2022070605/5a4d1adb7f8b9ab059974e8b/html5/thumbnails/9.jpg)
Output
![Page 10: 1 Chapter 4 – Decisions 4.1 Relational and Logical Operators (see other set of slides) 4.2 If Blocks (see other set of slides) 4.3 Select Case Blocks (see.](https://reader036.fdocuments.net/reader036/viewer/2022070605/5a4d1adb7f8b9ab059974e8b/html5/thumbnails/10.jpg)
10
The Group Box Control• Group boxes are passive objects used to
group other objects together.• When you drag a group box, the attached
controls follow as a unit.• To attach controls to a group box, create
the group box and then place the controls into the group box.
![Page 11: 1 Chapter 4 – Decisions 4.1 Relational and Logical Operators (see other set of slides) 4.2 If Blocks (see other set of slides) 4.3 Select Case Blocks (see.](https://reader036.fdocuments.net/reader036/viewer/2022070605/5a4d1adb7f8b9ab059974e8b/html5/thumbnails/11.jpg)
11
Group Box Example
Three attached controls:
Button1Button2Button3
![Page 12: 1 Chapter 4 – Decisions 4.1 Relational and Logical Operators (see other set of slides) 4.2 If Blocks (see other set of slides) 4.3 Select Case Blocks (see.](https://reader036.fdocuments.net/reader036/viewer/2022070605/5a4d1adb7f8b9ab059974e8b/html5/thumbnails/12.jpg)
12
Radio Button Properties• To determine if the button is on or off
radButton.Checked
has value True if button is on.
• To turn a radio button on radButton.Checked = True
Question: what is the data type of the RadioButton’s Checked property?
![Page 13: 1 Chapter 4 – Decisions 4.1 Relational and Logical Operators (see other set of slides) 4.2 If Blocks (see other set of slides) 4.3 Select Case Blocks (see.](https://reader036.fdocuments.net/reader036/viewer/2022070605/5a4d1adb7f8b9ab059974e8b/html5/thumbnails/13.jpg)
13
Example 3: Form
radChild
radAdult
radSenior
radMinor
Radio buttons are intended for mutually exclusive choices.By placing them in a GroupBox control, you guarantee only one will be selected.
![Page 14: 1 Chapter 4 – Decisions 4.1 Relational and Logical Operators (see other set of slides) 4.2 If Blocks (see other set of slides) 4.3 Select Case Blocks (see.](https://reader036.fdocuments.net/reader036/viewer/2022070605/5a4d1adb7f8b9ab059974e8b/html5/thumbnails/14.jpg)
14
Example 4.4.3If radChild.Checked Then txtFee.Text = FormatCurrency(0)ElseIf radMinor.Checked Then txtFee.Text = FormatCurrency(5)ElseIf radAdult.Checked Then txtFee.Text = FormatCurrency(10)ElseIf radSenior.Checked Then txtFee.Text = FormatCurrency(7.5)Else MessageBox.Show("Must make a selection.")End If
![Page 15: 1 Chapter 4 – Decisions 4.1 Relational and Logical Operators (see other set of slides) 4.2 If Blocks (see other set of slides) 4.3 Select Case Blocks (see.](https://reader036.fdocuments.net/reader036/viewer/2022070605/5a4d1adb7f8b9ab059974e8b/html5/thumbnails/15.jpg)
15
Example 4.4.3: Output
![Page 16: 1 Chapter 4 – Decisions 4.1 Relational and Logical Operators (see other set of slides) 4.2 If Blocks (see other set of slides) 4.3 Select Case Blocks (see.](https://reader036.fdocuments.net/reader036/viewer/2022070605/5a4d1adb7f8b9ab059974e8b/html5/thumbnails/16.jpg)
16
The Check Box Control• Consists of a small square and a caption• Presents the user with a Yes/No choice• During run time, clicking on the check box
toggles the appearance of a check mark.• Checked property has value True when check
box is checked and False when not• CheckedChanged event is raised when the
user clicks on the check box
![Page 17: 1 Chapter 4 – Decisions 4.1 Relational and Logical Operators (see other set of slides) 4.2 If Blocks (see other set of slides) 4.3 Select Case Blocks (see.](https://reader036.fdocuments.net/reader036/viewer/2022070605/5a4d1adb7f8b9ab059974e8b/html5/thumbnails/17.jpg)
17
Example 4.4.4: Form
chkDrug
chkDentalchkVision
chkMedical
Check boxes are intended for allowing multiple selections. This happens regardless of whether or not they are placed in a GroupBox.
![Page 18: 1 Chapter 4 – Decisions 4.1 Relational and Logical Operators (see other set of slides) 4.2 If Blocks (see other set of slides) 4.3 Select Case Blocks (see.](https://reader036.fdocuments.net/reader036/viewer/2022070605/5a4d1adb7f8b9ab059974e8b/html5/thumbnails/18.jpg)
Example 4.4.4: Code for ButtonDim sum As Double = 0If chkDrugs.Checked Then sum += 39.15End IfIf chkDental.Checked Then sum += 10.81End IfIf chkVision.Checked Then sum += 2.25End IfIf chkMedical.Checked Then sum += 55.52End IftxtTotal.Text = FormatCurrency(sum)
18
![Page 19: 1 Chapter 4 – Decisions 4.1 Relational and Logical Operators (see other set of slides) 4.2 If Blocks (see other set of slides) 4.3 Select Case Blocks (see.](https://reader036.fdocuments.net/reader036/viewer/2022070605/5a4d1adb7f8b9ab059974e8b/html5/thumbnails/19.jpg)
Example 4.4.4: Output
19
![Page 20: 1 Chapter 4 – Decisions 4.1 Relational and Logical Operators (see other set of slides) 4.2 If Blocks (see other set of slides) 4.3 Select Case Blocks (see.](https://reader036.fdocuments.net/reader036/viewer/2022070605/5a4d1adb7f8b9ab059974e8b/html5/thumbnails/20.jpg)
Events Raised by a Selection
• SelectedIndexChanged – raised when a new item of a list box is selected
• CheckedChanged - raised when the user clicks on an unchecked radio button or a check box; that is, when the value of the Checked property is changed.
20
![Page 21: 1 Chapter 4 – Decisions 4.1 Relational and Logical Operators (see other set of slides) 4.2 If Blocks (see other set of slides) 4.3 Select Case Blocks (see.](https://reader036.fdocuments.net/reader036/viewer/2022070605/5a4d1adb7f8b9ab059974e8b/html5/thumbnails/21.jpg)
21
Example 5: Code
Here, a single event procedure is handling multiple events. In this case, whichever CheckBox’s Checked status gets changed will trigger the procedure to execute.
![Page 22: 1 Chapter 4 – Decisions 4.1 Relational and Logical Operators (see other set of slides) 4.2 If Blocks (see other set of slides) 4.3 Select Case Blocks (see.](https://reader036.fdocuments.net/reader036/viewer/2022070605/5a4d1adb7f8b9ab059974e8b/html5/thumbnails/22.jpg)
22
Example 5: Output