Chapter 4 - PowerPoint PPT Presentation

About This Presentation
Title:

Chapter 4

Description:

Chapter 4 Decisions 4.1 Relational and Logical Operators (see other set of s) 4.2 If Blocks (see other set of s) 4.3 Select Case Blocks (see other set ... – PowerPoint PPT presentation

Number of Views:8
Avg rating:3.0/5.0
Slides: 23
Provided by: cwy5
Learn more at: http://cob.jmu.edu
Category:
Tags: chapter

less

Transcript and Presenter's Notes

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

2
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

3
The Three Types of Controls Used for Selection
list box
Which would you use for Age? Ethnicity?
radio buttons
check boxes
4
Fill a List Box at Design Time via its String
Collection Editor
Tasks button
click here to invoke string collection editor
5
String Collection Editor
Fill by direct typing or by copying and pasting
from a text editor or a spreadsheet.
6
List Box at Run Time
lstMonths
selected item
The value of lstMonths.Text is the string
consisting of the selected item.
7
Example 4.4.1 Form Designer
Items property
Collections editor
8
Code
Selection by user
9
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 Button1 Button2 Button3
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
RadioButtons Checked property?
13
Example 3 Form
radChild
radMinor
radAdult
radSenior
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.3
  • If 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
chkDental
chkVision
chkMedical
Check boxes are intended for allowing multiple
selections. This happens regardless of whether or
not they are placed in a GroupBox.
18
Example 4.4.4 Code for Button
  • Dim sum As Double 0
  • If chkDrugs.Checked Then
  • sum 39.15
  • End If
  • If chkDental.Checked Then
  • sum 10.81
  • End If
  • If chkVision.Checked Then
  • sum 2.25
  • End If
  • If chkMedical.Checked Then
  • sum 55.52
  • End If
  • txtTotal.Text FormatCurrency(sum)

19
Example 4.4.4 Output
20
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.

21
Example 5 Code
Here, a single event procedure is handling
multiple events. In this case, whichever
CheckBoxs Checked status gets changed will
trigger the procedure to execute.
22
Example 5 Output
Write a Comment
User Comments (0)
About PowerShow.com