CSET 3250 Client-Side Scripting VBScript : Operators, Control Structures, Procedures and Functions.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

“Going loopy with Visual Basic!”
1 Chapter Five Selection and Repetition. 2 Objectives How to make decisions using the if statement How to make decisions using the if-else statement How.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
CS0004: Introduction to Programming Repetition – Do Loops.
Do/Loops A loop repeats a series of instructions. An iteration is a single execution of the statement(s) in the loop. Used when the exact number of iterations.
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.
Iteration (Looping Constructs in VB) Iteration: Groups of statements which are repeatedly executed until a certain test is satisfied Carrying out Iteration.
Chapter 6 - Repetition. Introduction u Many applications require certain operations to be carried out more than once. Such situations require repetition.
Control Structures: Part 2. Introduction Essentials of Counter-Controlled Repetition For / Next Repetition Structure Examples Using the For / Next Structure.
An Object-Oriented Approach to Programming Logic and Design Chapter 6 Looping.
5.05 Apply Looping Structures
Lecture Set 5 Control Structures Part D - Repetition with Loops.
Chapter 12: How Long Can This Go On?
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
Mr. Dave Clausen1 La Cañada High School Chapter 6: Repetition Statements.
Compunet Corporation1 Programming with Visual Basic.NET While, Do and For – Next Loops Week 5 Tariq Ibn Aziz.
Controlling Execution Programming Right from the Start with Visual Basic.NET 1/e 8.
Statements That Repeat. For...Next Loop Structure For counter = start To end Step increment statements Next counter Where Counter is tested to see if.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
Computer Science Department LOOPS. Computer Science Department Loops Loops Cause a section of your program to be repeated a certain number of times. The.
An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
PHP Constructs Advance Database Management Systems Lab no.3.
Lab 4 Range Review, Control Logic and Loops ► Range Review ► Control Logic and Loops ► Exercise.
L OO P S While writing a program, there may be a situation when you need to perform some action over and over again. In such situation you would need.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
259 Lecture 11 Spring 2013 Advanced Excel Topics – Loops.
Pascal Programming Iteration (looping) Carl Smith National Certificate Unit 4.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Loops cause a section of a program to be repeated a certain number of times. The repetition continues while a condition remains true. When a condition.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Visual Basic Objects / Properties / Methods PropertyAdjective ObjectNoun Part of the application Attribute MethodVerb Action to do something.
For…Next and Do...While Loops! Happy St. Patrick’s Day!
Controlling Program Flow with Looping Structures
5.1 Introduction Problem Solving –Requires understanding of: Building blocks Program-construction principles BZUPAGES.COM.
Lab 6 (1) Range Review, Control Logic and Loops ► Control Logic and Loops ► Exercise.
Controlling Program Flow with Decision Structures.
Repetition Statements (Loops). 2 Introduction to Loops We all know that much of the work a computer does is repeated many times. When a program repeats.
Chapter 7: The Repetition Structure Introduction to Programming with C++ Fourth Edition.
 2002 Prentice Hall. All rights reserved. 1 Chapter 5 – Control Structures: Part 2 Outline 5.1Introduction 5.2 Essentials of Counter-Controlled Repetition.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Dani Vainstein1 VBScript Session 5. Dani Vainstein2 What we learn last session? Branching Branching using If … Then … Else statement. Branching using.
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
Control Structure  What is control Structure?  Types of Controls  Use the control structure in VBScript.  Example Summery.
C Program Control September 15, OBJECTIVES The essentials of counter-controlled repetition. To use the for and do...while repetition statements.
Loops causes program to execute the certain block of code repeatedly until some conditions are satisfied. Suppose you want to execute some code/s 10 times.
VB Script V B S.
UNIT 5 Lesson 15 Looping.
Chapter 5- Control Structures: Part 2
Visual Basic 6 (VB6) Data Types, And Operators
Problem Solving and Control Statements: Part 2
Control Structures: Part 2
Development of Internet Application 1501CT - Sara Almudauh
3rd prep. – 2nd Term MOE Book Questions.
JavaScript: Control Statements.
Control Structures: Part 1
VBScript Session 4 Dani Vainstein.
VBScript Session 7 Dani Vainstein.
CIS 16 Application Development Programming with Visual Basic
Problem Solving and Control Statements
Case & Repetitive Statements
Prepared By: Deborah Becker
PROGRAM FLOWCHART Iteration Statements.
ASP control structure BRANCHING STATEMENTS
Presentation transcript:

CSET 3250 Client-Side Scripting VBScript : Operators, Control Structures, Procedures and Functions

Operators VBScript has a full range of operators, including arithmetic operators, comparison operators, concatenation operators, and logical operators When several operations occur in an expression, each part is evaluated and resolved in a predetermined order. This is known as operator precedence Operations within parentheses are always performed before those outside

Operators

Conditional Loops The If...Then...Else statement is used to evaluate whether a condition is True or False and then to specify one or more statements to run, depending on the result If you want to run only one statement when a condition is True, you can use the single-line syntax of the If...Then...Else statement Sub FixDate() Dim myDate myDate = #5/4/01# if myDate < Now Then myDate = Now End Sub

Conditional Loops If you want to run more than one line of code, you must use the multiple-line syntax. This syntax includes the End If statement, as shown in the following example: Sub AlertUser(value) If value = 0 Then AlertLabel.ForeColor = vbRed AlertLabel.Font.Bold = True AlertLabel.Font.Italic = True End If End Sub

Conditional Loops You can use an If...Then...Else statement to define two blocks of executable statements: one block to run if the condition is True, the other block to run if the condition is False Sub AlertUser(value) If value = 0 Then AlertLabel.ForeColor = vbRed AlertLabel.Font.Bold = True AlertLabel.Font.Italic = True Else AlertLabel.Forecolor = vbBlack AlertLabel.Font.Bold = False AlertLabel.Font.Italic = False End If End Sub

Conditional Loops Looping allows you to run a group of statements repeatedly. Some loops repeat statements until a condition is False; others repeat statements until a condition is True. There are also loops that repeat statements a specific number of times. The following looping statements are available in VBScript: –Do...Loop: Loops while or until a condition is True –While...Wend: Loops while a condition is True –For...Next: Uses a counter to run statements a specified number of times

Do..Loops The While keyword is used to check a condition in a Do…Loop statement. You can check the condition before you enter the loop or you can check it after the loop has run at least once. Sub ChkFirstWhile() Dim counter,myNum counter = 0 myNum = 20 Do While myNum > 10 myNum = myNum - 1 counter = counter + 1 Loop MsgBox "The loop made " & counter & " repetitions." End Sub Sub ChkLastWhile() Dim counter, myNum counter = 0 myNum = 9 Do myNum = myNum - 1 counter = counter + 1 Loop While myNum > 10 MsgBox "The loop made " & counter & " repetitions.“ End Sub

Do..Loops Repeating a Statement Until a Condition Becomes True You can use the Until keyword to check a condition in a Do...Loop statement before you enter the loop or you can check it after the loop has run at least once. Sub ChkFirstUntil() Dim counter, myNum counter = 0 myNum = 20 Do Until myNum = 10 myNum = myNum – 1 counter = counter + 1 Loop MsgBox "The loop made " & counter & " repetitions." End Sub Sub ChkLastUntil() Dim counter, myNum counter = 0 myNum = 1 Do myNum = myNum + 1 counter = counter + 1 Loop Until myNum = 10 MsgBox "The loop made " & counter & " repetitions.“ End Sub

Do..Loops You can exit a Do...Loop by using the Exit Do statement. Because you usually want to exit only in certain situations, such as to avoid an endless loop, you should use the Exit Do statement in the True statement block of an If...Then...Else statement Sub ExitExample() Dim counter, myNum counter = 0 myNum = 9 Do Until myNum = 10 myNum = myNum - 1 counter = counter + 1 If myNum < 10 Then Exit Do Loop MsgBox "The loop made " & counter & " repetitions." End Sub

For…Next You can use For...Next statements to run a block of statements a specific number of times For loops, use a counter variable whose value is increased or decreased with each repetition of the loop For example, the following procedure causes a procedure called MyProc to execute 50 times The For statement specifies the counter variable x and its start and end values The Next statement increments the counter variable by 1 Sub DoMyProc50Times() Dim x For x = 1 To 50 MyProc Next End Sub Using the Step keyword, you can increase or decrease the counter variable by the value you specify To decrease the counter variable, you use a negative Step value

Procedures In VBScript there are two kinds of procedures; the Sub procedure and the Function procedure A procedure is defined by a Sub statement and ends with an End Sub statement A procedure is defined using the following structure: Sub ProcedureName(ArgumentList) VbScript Code End Sub Example: Sub DisplayName(strFirstName, strLastName) alert("Welcome " & strFirstName & " " & strLastName) End Sub

Procedures In order to call a procedure, it is sufficient to simply use the name of the procedure: DisplayName "Arman", "Danesh" Procedures can also be called using the Call statement: Call DisplayName("Arman", "Danesh")

Functions A Function procedure is a series of VBScript statements enclosed by the Function and End Function statements A Function procedure is similar to a Sub procedure, but can also return a value A Function procedure can take arguments (constants, variables, or expressions that are passed to it by a calling procedure) If a Function procedure has no arguments, its Function statement must include an empty set of parentheses A Function returns a value by assigning a value to its name in one or more statements of the procedure The return type of a Function is always a Variant

Example Function Sub ConvertTemp() temp = InputBox("Please enter the temperature in degrees F.", 1) MsgBox "The temperature is " & Celsius(temp) & " degrees C. “ End Sub Function Celsius(fDegrees) Celsius = (fDegrees - 32) * 5 / 9 End Function

Functions(contd) To use a Function in your code, it must always be used on the right side of a variable assignment or in an expression. For example : Temp = Celsius(fDegrees) or MsgBox "The Celsius temperature is " & Celsius(fDegrees) & " degrees."

Assignment Download the examples for this topic –Unzip them on your local machine –Load each into your browser in turn –After determining what each does, look at the source code to see how it is done –Modify any of the examples as needed to make them fully functional (correct any errors) FTP the examples to the server and run them from the server