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.

Slides:



Advertisements
Similar presentations
Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Advertisements

CSI 1306 PROGRAMMING IN VISUAL BASIC PART 2. Part 2  1. Strings  2. Translating Conditional Branch Instructions  3. Translation Set 2  4. Debugging.
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
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.
Basic Elements of Programming A VB program is built from statements, statements from expressions, expressions from operators and operands, and operands.
The number of calories burned per hour by cycling, jogging and swimming are 200, 475 and 275 respectively. A person loses 1pound of weight for each 3500.
CSCI 116 Decisions & Validation. Overview Constants Boolean conditions Decision logic Form validation 2.
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
CSC110 Fall Chapter 5: Decision Visual Basic.NET.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
JavaScript, Fourth Edition
JavaScript, Third Edition
VB Code Statements 3 types of VB statement The Remark statement, known as comments, are used for project documentation only Begin with an apostrophe Not.
A variable (X) is declared as an integer Data Type, meaning it can only accept numeric values The Text Box is named BoxContents The Variable X is assigned.
String Escape Sequences
The Data Element. 2 Data type: A description of the set of values and the basic set of operations that can be applied to values of the type. Strong typing:
CIS162AD - C# Decision Statements 04_decisions.ppt.
Microsoft Visual Basic 2008: Reloaded Fourth Edition
CS0004: Introduction to Programming Relational Operators, Logical Operators, and If Statements.
Decision Structures and Boolean Logic
2440: 211 Interactive Web Programming Expressions & Operators.
Using the selection structure (Unit 7) Visual Basic for Applications.
Announcements 1st homework is due on July 16, next Wednesday, at 19:00 Submit to SUCourse About the homework: Add the following at the end of your code.
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
Flow of Control Part 1: Selection
Making Decisions. 4.1 Relational Operators Used to compare numbers to determine relative order Operators: > Greater than < Less than >= Greater than.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 4: Making Decisions.
1 Scripting Languages VBScript - Recognized mainly by Internet Explorer only - Netscape does have a plug-in JavaScript - Recognized by Internet Explorer.
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.
Java Programming Fifth Edition Chapter 5 Making Decisions.
Chapter 5: Making Decisions. Objectives Plan decision-making logic Make decisions with the if and if…else structures Use multiple statements in if and.
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.
Characters and Strings
Visual Basic Review LBS 126. VB programming Project Form 1Form 2Form 3 Text boxButton Picture box Objects Text box Button Objects.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 4: Making Decisions 1.
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.
Knowledge Base. Defining a Variable Dim statement Dim intXX As Integer Public in a Module Public dblNN As Double.
Lecture 6 – Selection FTMK, UTeM – Sem /2014.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
TUTORIAL 4 Visual Basic 6.0 Mr. Crone. Pseudocode Pseudocode is written language that is part-code part- English and helps a programmer to plan the layout.
Random Functions Selection Structure Comparison Operators Logical Operator
Chapter 4: Decisions and Conditions
Java Programming Fifth Edition
Chapter 4: Decisions and Conditions
Visual Basic 6 (VB6) Data Types, And Operators
Chapter 4: Making Decisions.
JavaScript Objects.
Chapter 3 Branching Statements
Multiple variables can be created in one declaration
Topics The if Statement The if-else Statement Comparing Strings
Chapter 4: Making Decisions.
Making Decisions in a Program
Topics The if Statement The if-else Statement Comparing Strings
Chapter 6 Variables What is VBScript?
Objectives After studying this chapter, you should be able to:
Control Structures: Selection Statement
T. Jumana Abu Shmais – AOU - Riyadh
Fundamentals of visual basic
Microsoft Visual Basic 2005: Reloaded Second Edition
The Data Element.
Chapter 5 Decisions.
Control Structures: Selection Statement
The Selection Structure
The Data Element.
Decision Making Using the IF and EVALUATE Statements
Presentation transcript:

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 in MaxPrice) Even though an equal sign (=) means replacement in an assignment statement, in a relation test (using relational operators) an equal sign is used to test for equality

Comparing Strings String variables can be compared to other string variables or ‘string literals’ enclosed in quotation marks The comparison begins with the Left-Most character and proceeds one character at a time from left to right Each character is compared in the strings, and as soon as one is less than another the comparison is terminated and the string with the lower ranking character is judged less than the other The determination of which character is less than other is based on the code used to store characters internally in the computer

ASCII code (American Standard Code for Information Interchange) has an established order called the collating sequence, for all letters, numbers, and special characters All numeric digits are less than all letters Comparing the Text Property of Text Boxes The Text Property can behave like a Variant, a String, a Number A numeric expression/calculation on a Text Property can be forced by using the Val function

Testing for Boolean (True/False) If X = True Then…. is equivalent to: If X Then…. Boolean Variables hold the value ‘0’ when False, and ‘-1’ when True Any variable can be tested for ‘True’/‘False’ VB considers any numeric variable with a value of ‘0’ to be False, any other value will evaluate True The variable or expression is referred to as an ‘implied condition’ iCounter = 10 If iCounter = 10 Then... If iCounter Then...

Comparing Uppercase and Lowercase Characters When comparing strings, the case of the characters is important An Uppercase character is not equal to a Lowercase character By using the String Function Ucase or Lcase, the Uppercase or Lowercase equivalent of a string can be compared Ucase(string) Lcase(string)

Text1.Text Ucase(Text1.Text) Lcase(Text1.Text) User types in Basic BASIC basic If Ucase(Text1.Text) = “BASIC” Then Print “Hello” End If When the text of Text1 is converted to Uppercase, it must be compared to an Uppercase ‘Literal’ (BASIC), if it is to evaluate True

Select Case Statements (Case Structure) A Select Case statement executes one of several groups of statements, depending on the value of an expression An expression is selected and tested against a number of possible cases The expression to be tested is usually a variable or object property There is no limit to the number of statements that can follow a Case statement If any of these cases match the value of the expression, the statements that follow are executed

Select Case statement syntax: Select Case [Expression] Case [Expression Value/Constant List] Statements Case [Expression Value] Statements Case [Expression Value] Statements Case Else Statements End Select

The [Expression Value/Constant List] is the value that is required to be matched, and can be of the following types: numeric or string type variable or constant a range of values a relational condition or a combination of these To test a single variable or expression for multiple values, the Case Structure provides a flexible and powerful solution Any program decisions that can be coded with a Case Structure can also be coded with Nested If Statements, but usually the Case structure is simpler and clearer

When using a Relational Operator the word Is must be used Case Is >= 100 To indicate a Range of Constants, use the word To Case 25 To 90 To test for a String Value, quotation marks must be included around the literals Case “Visual Basic” In using Strings, the case(Upper/Lower) of the characters must be exact between the expression being tested and the [Expression Value/Constant List] Select Case Ucase(Text1.Text) Case “VISUAL BASIC” A combination of Relational/Logical Operators, using Variables and Constants Case Is >= 10 AND Num1 <= 20

Although the Case Else clause is optional, generally it will be included in the Select Case statements The statements coded underneath Case Else will execute only if none of the other Case Conditions is matched The Case Else clause will provide checking for any invalid or unforeseen values of the expression being tested If the Case Else clause is omitted and none of the Case Conditions is True, the program will continue execution at the statement following the End Select If more than one Case value is matched by the expression, only the statements in the first Case clause will be executed, identifying a definite Hierarchy

Testing Option Buttons using the Case Structure The Case Structure is ideal for testing which Option Button is selected