Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.

Slides:



Advertisements
Similar presentations
COMPUTER PROGRAMMING I Essential Standard 5.02 Understand Breakpoint, Watch Window, and Try And Catch to Find Errors.
Advertisements

1.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 4 Making Decisions in a Program.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Chapter 4 Decisions and Conditions Programming In Visual Basic.NET.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
Chapter 4 Decisions and Conditions Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
Val Function A Function performs an action and returns a value The expression to operate upon, known as the argument, (or multiple arguments), must be.
Exploring Office Grauer and Barber 1 Creating More Powerful Applications: Introduction to VBA(Wk9)
Input Validation Check the values entered into a text box before beginning any calculations Validation is a form of ‘self-protection’, rejecting bad data.
Comparing Numeric Values If Val(Text1.Text) = MaxPrice Then (Is the current numeric value stored in the Text property of Text1 equal to the value stored.
CSC110 Fall Chapter 5: Decision Visual Basic.NET.
McGraw-Hill/Irwin Programming in Visual Basic 6.0 © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Update Edition Chapter 4 Decisions and Conditions.
Input Validation Check the values entered into a text box before beginning any calculations Validation is a form of ‘self-protection’, rejecting bad data.
C++ for Engineers and Scientists Third Edition
Programming with MATLAB. Relational Operators The arithmetic operators has precedence over relational operators.
© 1999, by Que Education and Training, Chapter 5, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach.
Microsoft Visual Basic 2008: Reloaded Fourth Edition
Chapter 4: The Selection Structure
CS0004: Introduction to Programming Relational Operators, Logical Operators, and If Statements.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
Chapter 4 P 1 Decisions and Conditions Control statements - seqeuncing - selection - repetition (picture later) - abstraction (procedure calls)
Chapter 4: The Selection Process in Visual Basic.
Chapter 4: The Selection Structure Programming with Microsoft Visual Basic 2005, Third Edition.
Chapter 4: The Selection Structure
1 Chapter 4: Selection Structures. In this chapter, you will learn about: – Selection criteria – The if-else statement – Nested if statements – The switch.
McGraw-Hill © 2010 The McGraw-Hill Companies, Inc. All rights reserved. Chapter 4 Decisions and Conditions.
Copyright © 2001 by Wiley. All rights reserved. Chapter 4: The Selection Process in Visual Basic Selection Process Two Alternative Structure If..Then..ElseIf.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
Tutorial 51 Programming Structures Sequence - program instructions are processed, one after another, in the order in which they appear in the program Selection.
Decisions and Debugging Part06dbg --- if/else, switch, validating data, and enhanced MessageBoxes.
CHAPTER FIVE Specifying Alternate Courses of Action: Selection Statements.
Input Validation Check the values entered into a text box before beginning any calculations Validation is a form of ‘self-protection’, rejecting bad data.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
OV Copyright © 2011 Element K Content LLC. All rights reserved.  Determine the Dialog Box Type  Capture User Input Creating an Interactive Worksheet.
1 Scripting Languages VBScript - Recognized mainly by Internet Explorer only - Netscape does have a plug-in JavaScript - Recognized by Internet Explorer.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
Chapter 3 Control Structures. The If…Then Statement The If…Then statement is a Decision statement = that executes a set of statements when a condition.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
CECS 5020 Computers in Education Visual Basic Variables and Constants.
110 F-1 Decisions and Conditions Chapter 4: We can design a form We can calculate To make our programs more powerful, we need to be able to make choices.
Controlling Program Flow with Decision Structures.
Microsoft Visual Basic 2012 CHAPTER FIVE Decision Structures.
Chapter 10 So Many Paths … So Little Time (Multiple-Alternative Selection Structures) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Knowledge Base. Defining a Variable Dim statement Dim intXX As Integer Public in a Module Public dblNN As Double.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
Chapter 4: Decisions and Conditions
A variable is a name for a value stored in memory.
Chapter 4: Decisions and Conditions
Computer Programming I
Javascript Conditionals.
CHAPTER FIVE Decision Structures.
Making Decisions in a Program
Tutorial 12 – Security Panel Application Introducing the Select Case Multiple-Selection Statement Outline Test-Driving the Security Panel Application.
Chapter 3: Introduction to Problem Solving and Control Statements
Objectives After studying this chapter, you should be able to:
VB Decisions, Conditions & If
Decisions and Conditions
Visual Basic – Decision Statements
Microsoft Visual Basic 2005: Reloaded Second Edition
VB Decisions & Conditions
The Selection Structure
Presentation transcript:

Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San Diego

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Ch4: Decisions and Conditions  Block If statements  Nested If statements  Evaluating Conditions and Relational Operators  Testing Values with option buttons & check boxes  Validating input numeric fields  Creating Message boxes  Calling event procedures  Debugging with breakpoints & stepping execution

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Decision Making  Alternative courses of action are required in a program  The IF statement provides one of these structures  There are two types of IF statements –Single-line IF statement –Multi-line IF statement

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Comparison Operators SymbolMeaning >Greater than <Less than =Equal to <=Less than or equal to >=Greater than or equal to <>Not equal to

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill IF Statement Structure (1) Sleepy? Go to bed True False Form: If condition Then statement(s) End If

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill IF Statement Structure (2) Is SAT > 600? Admit Do Not Admit TrueFalse Form: If condition Then t-statement(s) Else f-statement(s) End If

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill IF Statement Structure (3) Form: If condition-1 Then If condition-2 Then t-statement-2 Else f-statement-2 End If Else f-statement-1 End If False Is SAT > 600? Do Not Admit True Is GPA > 3.75? Admit True Consider False

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Conditions  Comparing Numeric Variables & Constants  Comparing Strings  Comparing text property of text boxes  Uppercase and lowercase character comparisons  Compound conditions

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill If & opt. buttons & check boxes  If chkFlag = True Then imgFlag.Visible = True  If optDisplayForm Then frmSecond.Show

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Compound Conditions  If a1 a4 and a5 < a6 Then  And has precedence over Or  All comparison operators have precedence over all logical operators  Use parentheses to alter the order of evaluation

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill "If" statement and option buttons

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Displaying Messages in Message boxes  Special window displaying message to user  Form: MsgBox “message” [,buttons][, “t.b. caption”]  Example: MsgBox “Numeric ID only”, vbOkOnly, “Error”

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Displaying a Message String  Use & to concatenate strings (“Concatenate” means join end to end)  The VB intrinsic constant vbCRLF creates a new line in a string MsgBox stMessage, vbOKOnly, stTitle

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Message box return values ConstantValueDescription vbOK1OK button pressed. vbCancel2Cancel button pressed. vbAbort3Abort button pressed. vbRetry4Retry button pressed. vbIgnore5Ignore button pressed. vbYes6Yes button pressed. vbNo7No button pressed.

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Input Validation  Checking a data type: IsNumeric & IsDate  IsNumeric checks & returns true or false If IsNumeric(txtQty.Text) Then lblDue.Caption = curPrice + Val(txtQty)  Validating value ranges If Val(txtHours.Text) > 10 And _ Val(txtHours.Text) <= 80 Then...

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Data Validation  IsDate returns true or false depending on whether or not a value is a date If IsDate(txtData) Then …  the VarType function return a number that corresponds to the data type stored in a variant. If VarType(varValue) = 0 Then...

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Using LostFocus to Validate  LostFocus is a way to validate check boxes before allowing user to go on.  But is it a good way?  Consider the code If txtUserName.Text = "" Then txtUserName.SetFocus  Problem: some object gets focus and you cannot have allow both objects to be tested using the LostFocus event.

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Calling Event Procedures  An event procedure is a subprocedure that reacts to a specific event such as a button click.  You can call any given event procedure from multiple locations, as long as the procedure is in the same form or is public  Example: Call cmdCalculate_Click  Suffix is event, prefix is object name

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Hands on Programming Example

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Debugging VB Projects  Debug projects by setting code breakpoints –Run the project, –Step through the code window at break time by pressing F8, –Point to variables above executed code lines to view their current values (see program shot in Notes portion of this slide)

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Debugging continued  You can choose "Step into" or "Step over"  Step into traces all code execution, including traversing down into subprocedures  Step over stays with current subprocedure only, not showing any called routines' code