JK VB NET 5 Decision Making Structures
JK VB NET 5 Decision Making Structures
Topics
• This presentation covers the Visual
Basic .NET decision statements
• If … Then
• ElseIf
• Case statement
• It also discusses the use of
• Radio Buttons and check boxes
• Message Boxes
The Decision Structure
• Flowchart of a
typical decision
structure True
Condition
• Evaluate the
False
condition
Conditional
• Execute, or not Code
some code
• Dim age As Integer
• age = txtage.Text
• If age >= 18 Then
• lbloutput.Text = "you can vote"
• End If
The If…Then Statement
If condition Then
statement
(more statements as needed)
End If
End Sub
End Class
If…Then Rules
If x + y > a - b Then
lblMessage.Text = "It is true!"
End If
What an 'If…Then' Really Tests For
False True
Condition
Execute Execute
If False If True
'If…Then…Else' Example
series of mutually If
exclusive choices
it is very cold Then
• In pseudo code: Wear a coat
Elseif it is chilly
Wear a light
jacket
Elseif it is windy
Wear a windbreaker
Elesif it is hot
Wear no jacket
In Visual Basic .NET Syntax
If condition1 Then
Statement(s)1
Elseif condition2 Then
Statements(s)2
Elseif condition3 Then
Statements3
…
End If
In Flowchart Form
True
C1 Statement(s)1
False
True
C2 Statement(s)2
False
True
C3 Statement(s)3
False
Example of Usage
If average < 60 Then
lblGrade.Text = "F"
ElseIf average < 70 Then
lblGrade.Text = "D"
ElseIf average < 80 Then
lblGrade.Text = "C"
ElseIf average < 90 Then
lblGrade.Text = "B"
ElseIf average <= 100 Then
lblGrade.Text = "A"
End If
The (Optional) Trailing Else
Operator Effect
And Both operands must be true for the overall
expression to be true, otherwise it is false
Or One or both operands must be true for the overall
expression to be true, otherwise it is false
Xor One operand (but not both) must be true for the
overall expression to be true, otherwise it is false
Not Reverses the logical value of an expression
The 'And' Operator
Truth Table for 'And' Operator
Expression 1 Expression 2 Expression 1 And Expression 2
True False False
False True False
False False False
True True True