Decision Statements If - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

Decision Statements If

Description:

The real power of a program comes from the ability to change ... txt.Title.Font.Italic = True. Else. txtTitle.Font.Italic = False. End If. Nested If Statements ... – PowerPoint PPT presentation

Number of Views:27
Avg rating:3.0/5.0
Slides: 13
Provided by: horto3
Category:

less

Transcript and Presenter's Notes

Title: Decision Statements If


1
Decision StatementsIf Then and Select Case
2
Decision Statements
  • The real power of a program comes from the
    ability to change the order of execution using
    control structures.
  • There are two statement structures available in
    VB for making decisions.
  • The IfThenElse statement is useful when making
    true/false type decisions.
  • The Select Case statement is best used for
    multiple-choice type decisions.

3
Decision Statements
  • The If statement executes a statement when a
    statement condition is true. The statement
    executes another statement when the condition is
    false.
  • Syntax If ( condition) Then
  • statement(s)
  • Else
  • statement(s)
  • End If

4
Flow Chart
5
If Statement
  • If the sun is shining Then
  • go to beach
  • Else
  • go to class
  • End If
  • Condition- sun is shining, statement 1- go to
    beach,
  • statement 2 - go to class

6
Comparison Conditions
  • gt greater than
  • lt less than
  • equal
  • ltgt not equal to
  • gt greater than or equal to
  • lt less than or equal to

7
Compound Conditions
  • You can use compound conditions to test more than
    one condition. Create compound conditions by
    joining conditions with logical operators, Or,
    And, and Not.
  • Ex.
  • If optMale.Value True And Val(txtAge.Text) lt21
    Then
  • intMinorMaleCount intMinorMaleCount 1
  • End If

8
Option Buttons and Check Boxes
  • Now that you understand If Statements, we can add
    functionality to option buttons and check boxes.
  • Option buttons and Check boxes must always be
    created within a frame on the form, otherwise
    they will not work.
  • With an If statement we can check the state of
    the button or box and create events based on this
    information.

9
Option Buttons and Check Boxes
  • For example,
  • If chkBlue.Value True Then
  • lblName.BackColor vbBlue
  • End If
  • Or
  • If optItalic.Value True Then
  • txt.Title.Font.Italic True
  • Else
  • txtTitle.Font.Italic False
  • End If

10
Nested If Statements
  • If statements that contain additional If
    statements are said to be nested If statements.
  • P.130 go over possible forms of nested ifs
  • Temp Example, can be either Hot, Moderate or
    Freezing.

11
Select Case Statements
  • Evaluates a condition at the beginning of the
    statement. The result of this evaluation is
    compared with the values for each Case when a
    match is found the statements associated with it
    are executed.
  • For example, lets look at a situation where we
    are interested in an applicants age so that we
    can determine demographics in an area.

12
Select Case Statements
  • Select Case intApplicantAge
  • Casegt17
  • blnDrivingAge True
  • blnVotingAge True
  • Case gt15
  • blnDrivingAge True
  • blnVotingAge False
  • Case Else
  • blnDrivingAge False
  • blnVotingAge False
  • End Select
Write a Comment
User Comments (0)
About PowerShow.com