VBScript Conditional Statements. Conditional Statements Very often when you write code, you want to perform different actions for different decisions.

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

Fundamental of C programming
Chapter 13 Control Structures. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Control Structures Conditional.
Creating PHP Pages Chapter 7 PHP Decisions Making.
Objectives Using functions to organize PHP code
PHP Conditions MIS 3501, Fall 2014 Jeremy Shafer Department of MIS Fox School of Business Temple University September 11, 2014.
PHP Functions and Control Structures. 2 Defining Functions Functions are groups of statements that you can execute as a single unit Function definitions.
IS437: Fall 2004 Instructor: Dr. Boris Jukic Program Flow Control: Decisions and Conditions (Branching) Controlled Repetition (Looping)
July 13 th.  If/ Else if / Else  Variable Scope  Nested if/else's  Switch statements  Conditional Operator.
Slide 1 VB Program Flow Control. Slide 2 Making Decisions v Decision Statement: control the execution of parts of the program based on conditions. v The.
CIS 375—Web App Dev II VBScript. 2 Introduction to VBScript VBScript is a light version of MS’s ____________. Example: document.write("Hello from VBScript!")
Selection Statements choice of one among several blocks of code Java supports 3 kinds of selection statements: if statement – selects one block or leaves.
Chapter 4 Functions and Control Structures PHP Programming with MySQL.
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
Chapter 4: Control Structures: Selection
JavaScript Switch Statement. Switch JavaScript Switch Statement If you have a lot of conditions, you can use a switch statement instead of an if…elseif…
آموزش طراحی وب سایت جلسه دهم – جاوا اسکریپت 1 تدریس طراحی وب برای اطلاعات بیشتر تماس بگیرید تاو شماره تماس: پست الکترونیک :
CIS 115 Lecture 7 Selection / Decisions.
Conditional Statements While writing a program, there may be a situation when you need to adopt one path out of the given two paths. So you need to make.
Nael Alian Introduction to PHP
Python – Making Decisions Lecture 02. Control Structures A program that only has one flow is useful but limited. We can use if statements to make these.
Engineering 1020 Introduction to Programming Peter King Winter 2010.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
COMPUTER PROGRAMMING. Control Structures A program is usually not limited to a linear sequence of instructions. During its process it may repeat code.
CIS 375—Web App Dev II JavaScript II.
PHP Conditional Statements Conditional statements in PHP are used to perform different actions based on different conditions. Conditional Statements Very.
PHP Programming with MySQL Slide 4-1 CHAPTER 4 Functions and Control Structures.
VBScript. Introduction Visual Basic scripting language is client side scripting language. It is developed by Microsoft VBScript is subset of VB language.
Chapter 2 Functions and Control Structures PHP Programming with MySQL 2 nd Edition.
Control Structures By Shyam Gurram. Control Structure In this chapter we have two different types of structures. Conditional Structure Iterative Control.
Basics 2. Write a macro that … … uses a popup message box to say Hello. (msgbox ”Hello”) … writes the contents of the active cell in a message box. (you.
MULTIPLE ALTERNATIVES IF… THEN… ELSEIF SELECT CASE.
LOGO Conditional Statements & Loops in JavaScript CHAPTER 10 Eastern Mediterranean University School of Computing and Technology Department of Information.
Conditional Expression One of the most useful tools for processing information in an event procedure is a conditional expression. A conditional expression.
PEG200/Saidatul Rahah 1.  Selection Criteria › if..else statement › relational operators › logical operators  The if-then-else Statement  Nested if.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
IT ELECTIVE 2.  Web server Can refer to either the hardware (the computer) or the software (the computer application) that helps to deliver content that.
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.
More Python!. Lists, Variables with more than one value Variables can point to more than one value at a time. The simplest way to do this is with a List.
COMPUTER PROGRAMMING I 5.04 Apply Decision Making Structures.
© 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 4: Chapter 4: Slide 1 Unit 4 Decisions Chapter 4 Making Decisions and Working.
1 Microsoft® Visual Basic®.NET Language # 2. 2 Flow-Control Statements If … End If Select Case … End Select For… Next Do … Loop Exit.
Lab 6 (1) Range Review, Control Logic and Loops ► Control Logic and Loops ► Exercise.
CRE Programming Club - Class 4 Robert Eckstein and Robert Heard.
Controlling Program Flow with Decision Structures.
Controlling Program Flow with Decision Structures.
JavaScript JavaScript ( Condition and Loops ). Conditional Statements If Statement If...else Statement if (condition) { code to be executed if condition.
Control Structure  What is control Structure?  Types of Controls  Use the control structure in VBScript.  Example Summery.
ME 142 Engineering Computation I Condition Statements.
LECTURE # 7 : STRUCTURED PROGRAMMING Selection Statements Tr.Hadeel.
Slide 1 Chapter 4 The If…Then Statement  Conditional control structure, also called a decision structure  Executes a set of statements when a condition.
 Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do.
PHP Condtions and Loops Prepared by Dr. Maher Abuhamdeh.
Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do this.
5.04 Apply Decision Making Structures
VB Script V B S.
My First Web Page document.write("" + Date() + ""); To insert.
Development of Internet Application 1501CT - Sara Almudauh
Control Structures: Part 1
Topics The if Statement The if-else Statement Comparing Strings
VBScript Session 4 Dani Vainstein.
Chapter (3) - Looping Questions.
Logical Operations In Matlab.
Selection Statements.
JavaScript Part 2.
Control Structures Part 3
Relational Operators.
ASP control structure BRANCHING STATEMENTS
Chapter 3: Selection Structures: Making Decisions
statement. Another decision statement, , creates branches for multi-
Presentation transcript:

VBScript Conditional Statements

Conditional Statements Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do this.

In VBScript we have three conditional statements: if...then...else statement - use this statement if you want to select one of two sets of lines to execute if...then...elseif statement - use this statement if you want to select one of many sets of lines to execute select case statement - use this statement if you want to select one of many sets of lines to execute

If....Then.....Else You should use the If...Then...Else statement if you want to execute some code if a condition is true select one of two blocks of code to execute

If you want to execute only one statement when a condition is true, you can write the code on one line: if i=10 Then msgbox "Hello“ There is no..else.. in this syntax. You just tell the code to perform one action if the condition is true (in this case if i=10).

If you want to execute more than one statement when a condition is true, you must put each statement on separate lines and end the statement with the keyword "End If": if i=10 Then msgbox "Hello" i = i+1 end If There is no..else.. in this syntax either. You just tell the code to perform multiple actions if the condition is true.

If you want to execute a statement if a condition is true and execute another statement if the condition is not true, you must add the "Else" keyword: if i=10 then msgbox "Hello" else msgbox "Goodbye" end If The first block of code will be executed if the condition is true, and the other block will be executed otherwise (if i is not equal to 10).

If....Then.....Elseif You can use the if...then...elseif statement if you want to select one of many blocks of code to execute: if payment="Cash" then msgbox "You are going to pay cash!" elseif payment="Visa" then msgbox "You are going to pay with visa." elseif payment="AmEx" then msgbox "You are going to pay with American Express." else msgbox "Unknown method of payment." end If

Select Case You can also use the SELECT statement if you want to select one of many blocks of code to execute: select case payment case "Cash" msgbox "You are going to pay cash" case "Visa" msgbox "You are going to pay with visa" case "AmEx" msgbox "You are going to pay with American Express" case Else msgbox "Unknown method of payment“ end select

How it works This is how it works: First we have a single expression (most often a variable), that is evaluated once. The value of the expression is then compared with the values for each Case in the structure. If there is a match, the block of code associated with that Case is executed.

The if...then…else Statement function greeting() i=hour(time) if i < 10 then document.write("Good morning!") else document.write("Have a nice day!") end if end function

How it looks in a browser:

The if…then…elseif…statement function greeting() i=hour(time) If i = 10 then document.write("Just started...!") elseif i = 11 then document.write("Hungry!") elseif i = 12 then document.write("Ah, lunch-time!") elseif i = 16 then document.write("Time to go home!") else document.write("Unknown") end if end function

How it looks in a browser:

The Select Case Statement d=weekday(date) select case d case 1 document.write("Sleepy Sunday") case 2 document.write("Monday again!") case 3 document.write("Just Tuesday!") case 4 document.write("Wednesday!") case 5 document.write("Thursday...") case 6 document.write("Finally Friday!") case else document.write("Super Saturday!!!!") end select This example demonstrates the "select case" statement. You will receive a different greeting based on what day it is. Note that Sunday=1, Monday=2, Tuesday=3, etc.

How it looks in a browser: