Decisions with Select Case and Strings Chapter 4 Part 2.

Slides:



Advertisements
Similar presentations
1.
Advertisements

Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Programming with Microsoft Visual Basic th Edition
Microsoft Visual Basic: Reloaded Chapter Five More on the Selection Structure.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 03.
Chapter 5: More on the Selection Structure Programming with Microsoft Visual Basic.NET, Second Edition.
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.
VB.Net Decisions. The If … Then Statement If condition Then Statements End If If condition Then Statements Else Statements End If Condition: –Simple condition:
IS 1181 IS 118 Introduction to Development Tools VB Chapter 03.
Chapter Three Using Variables and Constants Programming with Microsoft Visual Basic th Edition.
Chapter 5 new The Do…Loop Statement
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Ten String Manipulation and Menus.
1.
Chapter 8: String Manipulation
Programming with Microsoft Visual Basic th Edition
Programming with Microsoft Visual Basic th Edition CHAPTER THREE USING VARIABLES AND CONSTANTS.
Chapter Four The Selection Structure
Microsoft Visual Basic 2008: Reloaded Fourth Edition
Chapter 4: The Selection Structure
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Five More on the Selection Structure.
08/10/ Iteration Loops For … To … Next. 208/10/2015 Learning Objectives Define a program loop. State when a loop will end. State when the For.
Chapter 4: The Selection Structure
Lecture Set 5 Control Structures Part A - Decisions Structures.
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter Five More on the Selection Structure.
Decisions and Debugging Part06dbg --- if/else, switch, validating data, and enhanced MessageBoxes.
Chapter 5: More on the Selection Structure Programming with Microsoft Visual Basic 2005, Third Edition.
CHAPTER FIVE Specifying Alternate Courses of Action: Selection Statements.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 24 The String Section.
Chapter 5: More on the Selection Structure
Programming with Microsoft Visual Basic th Edition
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
1.
Chapter Four The Selection Structure Programming with Microsoft Visual Basic th Edition.
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.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Programming with Microsoft Visual Basic th Edition
Tutorial 3: Using Variables and Constants1 Tutorial 3 Using Variables and Constants.
Copyright (c) 2003 by Prentice Hall Provided By: Qasim Al- ajmi Chapter 3 Some Visual Basic Controls and Events Visual Basic. NET.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Eight String Manipulation.
© 2006 Lawrenceville Press Slide 1 Chapter 6 The Post-Test Do…Loop Statement  Loop structure that executes a set of statements as long as a condition.
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.
Copyright © Don Kussee 1410-Ch5 #1031 CNS 1120 Chapter 5 Selection statements 1120-Ch5.PPT.
Chapter 23 The String Section (String Manipulation) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 11 So Many Paths … So Little Time.
Chapter 10 So Many Paths … So Little Time (Multiple-Alternative Selection Structures) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Chapter Five More on the Selection Structure Programming with Microsoft Visual Basic th Edition.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 5 Decision Making.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are used in programs so that values can be represented with.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration statement. For example: Dim.
© 2010 Lawrenceville Press Slide 1 Chapter 5 The Do…Loop Statement  Loop structure that executes a set of statements as long as a condition is true. 
Chapter 4: Decisions and Conditions
Microsoft Visual Basic 2008: Reloaded Third Edition
A variable is a name for a value stored in memory.
Chapter 4: Decisions and Conditions
The Selection Structure
Chapter 4: The Selection Structure
Programming with Microsoft Visual Basic 2008 Fourth Edition
More Selections BIS1523 – Lecture 9.
Making Decisions in a Program
Chapter 5 The Do…Loop Statement
Chapter 3: Introduction to Problem Solving and Control Statements
Objectives After studying this chapter, you should be able to:
Items, Group Boxes, Check Boxes & Radio Buttons
Microsoft Visual Basic 2005: Reloaded Second Edition
Presentation transcript:

Decisions with Select Case and Strings Chapter 4 Part 2

Chapter 42 String Storage (Section 4.8) Stores characters (e.g., A, a, B, b) as numeric codes in Unicode format. Displays character corresponding to actual Unicode number stored in memory. Arranges letters in alphabetical order in Unicode sequencing. A comes before B. A has lower Unicode number than B. Uppercase before lowercase: A before a Space before letters

Chapter 43 String Comparison in If Statement John (same) JOHN (different)

Chapter 44 More String Comparison John (equal) JOHN (less than John) Johnny (greater than John) Jones (greater than John)

Chapter 45 How Strings Are Compared JOHN JONES

Chapter 46 ToUpper StringExpression.ToUpper Returns uppercase equivalent of string. Does not change original string contents. Then store result in another variable.

Chapter 47 ToLower StringExpression.ToLower Returns lowercase equivalent of string. Does not change original string contents. Then store result in another variable.

Chapter 48 Tutorial 4-6 (pp ) Illustrates how to use ToUpper within an If statement to process comparisons. Shows that typing “prospero” equals “PROSPERO” when using: txtInput.Text.ToUpper

Chapter 49 StringExpression.Length Determines the length of a string. Text Box Example: Visual Basic (typed in text box) txtProgram.Text.Length Length = 17 Variable Example: strName = txtName.Text intNumber = strName.Length Good for getting restricted # of characters from user. (see p. 217)

Chapter 410 Spaces Leading Spaces Spaces (shown here with #) before actual characters #####Keith Trailing Spaces Spaces after actual characters Keith#####

Chapter 411 Trim Methods Use Trim method to remove spaces. StringExpression.TrimStart Removes leading spaces #####Keith becomes Keith StringExpression.TrimEnd Removes trailing spaces Keith##### becomes Keith StringExpression.Trim Removes leading and trailing spaces #####Keith##### becomes Keith Trim methods do not modify actual variable; use Trim and store results in another variable.

Chapter 412 TrimStart Example See p. 227 for displaying multiple lines.

Chapter 413 Other String Expressions Substring (pp ) IndexOf (pp )

Chapter 414 InStr Searches for a substring within the base string (searches are case-sensitive). Proceeds left to right. Stops at match or end of string. If successful, returns the character position at which the match was found. If unsuccessful, returns 0. Example: InStr("Eventful adventure","advent") Returns 10 because “a” starts in 10 th position. Eventful adventure (string) advent (substring

Chapter 415 More InStr() Instr(startpos, basestring, searchstring) Example: InStr(1,”Eventful adventure”, “vent”) Starts at position 1. Looks in Eventful adventure. Finds starting position of v in vent. Returns 2. Example: InStr(1, strWholeName, “,“) Looks within variable contents to find position of comma.

Chapter 416 Trim Full Name Example

Chapter 417 Trim Full Name, Continued

Chapter 418 Select Case Handles conditions with multiple outcomes. Tests one expression, whereas ElseIf tests several expressions. Select Case testexpression Case expressionlist1 Statementblock1 Case expressionlist2 Statementblock2 Case Else Statementblock End Select

Chapter 419 Select Case Exact Match Example

Chapter 420 Select Case at Run Time 1) Evaluates the test expression. 2) Attempts to match the resulting value with one of the expression lists. 1) Starts searching top of expression list. 2) Proceeds through subsequent expression lists, stopping at the first match. 3) Processes code at match or 4) Executes the Case Else statement block if no match is selected.

Chapter 421 Select Case for Ranges Select Case expression Case Is < 1 ‘requires Is before relational operator Do something Case 1 To 5 ‘requires To keyword between values Do something different Case 6 To 10 Do something Case Else Do something entirely different. End Select

Chapter 422 Select Case Example txtTest btnGrade 90+ Display A and “Superior” 80-89Display B and “Good” 70-79Display C and “Satisfactory” OtherDisplay failing notice

Chapter 423 Relational Operator >= And Range Selection

Chapter 424 Summary Select CaseIf Statement Test expression can be any numeric or string expression. Must be a logical expression, such as > <. Decision determined by a single expression at the top. Has one condition at the top and one for each ElseIf and each of these conditions is a separate expression. Appropriate for more “clear cut” examples. Enables more complexity than Select Case.

Chapter 425 Decision Rules Select CaseIf Statement Decision has multiple outcomes, which depend only on a single expression. Decision has only 2 outcomes & decision can be expressed as a single expression. Outcome depends on multiple conditions that may be independent of each other.

Chapter 426 Radio Button Control (p. 236) Ensures that the user selects only one option: Male/Female Age ranges Circle with descriptive text Only 1 selected in group at a time Mutually Exclusive: Deselects one when you select another radio button

Chapter 427 Radio Button Rules & Conventions Use radControlName style with rad prefix. Use access keys on Text property. Set TabIndex from one radio button to another. Must use group boxes if the form has more than one set of radio buttons (see bulleted list and examples on p. 236). Use no more than 7 radio buttons per set.

Chapter 428 Radio Button Properties NameControl name, such as radRed TextDescriptive text displayed by the circle CheckedSelection option value = True Not selected value = False TabIndexHelps with focus (active control)

Chapter 429 Radio Button Results Can trigger Click event, but typically enable user to choose and then click a button to trigger event. Default radio button Set Checked property to True.

Chapter 430 Which button is clicked? Use in IF…ElseIf statement to determine if radio button Checked property value is true (i.e., selected). If radRed.Checked = True Then MessageBox.Show(“You chose red.”) ElseIf radGreen.Checked = True Then MessageBox.Show(“You chose green.”) ElseIf radBlue.Checked = True Then MessageBox.Show(“You chose blue.”) ElseIf radPurple.Checked = True Then MessageBox.Show(“You chose purple.”) End If

Chapter 431 Check Box Control (p. 238) Not Mutually Exclusive: Enables user to select 0, 1, or more options in same category. Name: chk prefix standard chkBold chkItalic chkUnderline Text: caption displayed onscreen Checked: selected if True Can set 1 or more at design time See characteristics on p. 238.

Chapter 432 Is a check box checked? Although If…ElseIf statements work well for radio button groups, they do not work well for check boxes. Use individual If statements for each check box to see if it is checked. Use Checked to determine if check box is selected. chkBold.Checked = True Compare radio button code (p. 239) to check box code (p. 240).

Chapter 433 Class-Level Variables Review scope of a variable. Visible and accessible to statements Local variables Declared within event procedure; local to that procedure Class-level variables Declared at the form level; available to all procedures on that form

Chapter 434 Class-Level Concerns Wrong value can be stored; must track down code that causes problem (very troublesome in complex programs). When 2 or more procedures modify same variable, must be careful that 1 procedure doesn’t modify it when you need original value in another procedure.

Chapter 435 Recommended Practice Tutorial 4-7 (Strings) Tutorial 4-8 (Select Case) Tutorial 4-9 (Check Boxes & Radio Btns) Section 4-14 and Tutorial 10 pp Comprehensive review