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

Post on 06-Jan-2018

217 Views

Category:

Documents

2 Downloads

Preview:

Click to see full reader

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

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

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

The Three Types of Controls Used for Selection

3

list box

radio buttons check

boxes

Which would you use for:

Age? Ethnicity?

Fill a List Box at Design Time via its String Collection Editor

4

Tasks button

click here to invoke string collection editor

String Collection Editor

5

Fill by direct typing or by copying and pasting from a text editor or a spreadsheet.

List Box at Run Time

6

lstMonths

selected item

The value of lstMonths.Text is the string consisting of the selected item.

Example 4.4.1– Form Designer

Items property

Collections editor

Code

8

Selection by user

Output

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.

11

Group Box Example

Three attached controls:

Button1Button2Button3

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?

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.

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

15

Example 4.4.3: Output

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

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.

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

Example 4.4.4: Output

19

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

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.

22

Example 5: Output

top related