220 likes | 238 Views
Learn to implement selection structures in Visual Basic with If...Then...Else statements, comparison operators, and interface design with check boxes. Understand flowcharts, algorithms, variable scopes, and problem-solving approaches in programming.
E N D
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 9 Decisions, Decisions, Decisions
Objectives • Show the selection structure in both pseudocode and a flowchart • Write If…Then…Else statements • Include comparison operators in a selection structure’s condition • Add a check box to an interface Clearly Visual Basic: Programming with Visual Basic 2008
Someone Might Need to Make a Decision • All computer programs are written using one or more of three control structures • Sequence, selection, or repetition • Selection structure • Makes a decision and then takes appropriate action based on that decision • Studying problem specification • Determines whether problem’s solution requires a selection structure Clearly Visual Basic: Programming with Visual Basic 2008
Going Beyond Rob’s Problems Figure 9-5 shows: Problem specification that does not involve Rob, the mechanical man Correct algorithm for the problem Clearly Visual Basic: Programming with Visual Basic 2008
The If … Then … Else Statement • Comparison operators • Used to compare values • Statement block • Set of statements contained in the true path and the false path • All expressions containing a comparison operator • Will result in an answer of either True or False only Clearly Visual Basic: Programming with Visual Basic 2008
Examining Another Problem Specification • Oval in a flowchart • Is the start/stop symbol • Rectangle in a flowchart • Is the process symbol • Parallelogram in a flowchart • Is the input/output symbol • Diamond in a flowchart • Is called the selection/repetition symbol Clearly Visual Basic: Programming with Visual Basic 2008
Hey, That’s Not the Way I Would Have Done It • Variable that has procedure scope • Can be used anywhere within the procedure • Variable that has block scope • Can be used only within the statement block in which it is declared • Block variable • Variable declared within a statement block Clearly Visual Basic: Programming with Visual Basic 2008
Summary • Selection structure • One of the three control structures • Indent instructions in a selection structure’s true path and its false path • In Visual Basic • You can use the If…Then…Else statement to code the selection structure • An expression containing a comparison operator • Will always evaluate to either True or False Clearly Visual Basic: Programming with Visual Basic 2008
Summary (continued) • In a flowchart • The selection structure’s condition is represented by a diamond • chk • The three-character ID used when naming check boxes • Block variable • Has block scope Clearly Visual Basic: Programming with Visual Basic 2008