Professional Documents
Culture Documents
Chapter 4 Decisions and Conditions
Chapter 4 Decisions and Conditions
Decisions and
Conditions
Programming In
Visual Basic .NET
If Statements
If (condition) Then
statement(s)
[ElseIf (condition) Then Condition True
statement(s)] False
[Else
statement(s)] Statement Statement
End If
unitsDecimal = Decimal.Parse(unitsTextBox.Text)
If unitsDecimal < 32D Then
freshmanRadioButton.Checked = True
Else
freshmanRadioButton.Checked = False
End If
Condition 1
• Join conditions using logical operators
OR T F
– Or If one or both conditions True,
Condition 2
entire condition is True T T T
– And Both conditions must be True
F T F
for entire condition to be True
– Not Reverses the condition, a Condition 1
True condition will evaluate False
AND T F
and vice versa
Condition 2
T T F
F F F
4- 8 © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.
Compound Condition Examples
If maleRadioButton.Checked And _
Integer.Parse(ageTextBox.Text) < 21 Then
minorMaleCountInteger += 1
End If
Constant Description
CR Carriage Return
CRLF Carriage Return + Line Feed
NewLine Carriage Return + Line Feed
Tab Tab Character
NullChar Character with a Value of Zero
Quote Quotation Mark Character
ControlChars.NewLine
Used to force to next line
MessageBoxButtons.YesNo
whichButtonDialogResult = MessageBox.Show _
("Clear the current order figures?", "Clear Order", _
MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If whichButtonDialogResult = DialogResult.Yes Then
' Code to clear the order.
End If
• Reusable code
• General Form
– [Call] ProcedureName ( )
– Keyword Call is optional and rarely used
• Examples
– Call clearButton_Click (sender, e)
OR
– clearButton_Click (sender, e)
• Debug Menu
• Debug Toolbar
• Toggle BreakPoints on/off by clicking Editor's gray left
margin indicator
• Step through Code, Step Into, Step Over
• View the values of properties, variables, mathematical
expressions, and conditions
• Output Window
• Locals Window
• Autos Window
• Debug.WriteLine(TextString)
• Debug.WriteLine(Object)