1 chapter 4 – decisions 4.1 relational and logical operators (see other set of slides) 4.2 if...

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 other set of slides) 4.4 Input via User Selection

Upload: patrick-morgan

Post on 06-Jan-2018

217 views

Category:

Documents


2 download

DESCRIPTION

The Three Types of Controls Used for Selection 3 list box radio buttons check boxes Which would you use for: Age? Ethnicity? Which would you use for: Age? Ethnicity?

TRANSCRIPT

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

22

Example 5: Output