 2001 Prentice Hall, Inc. All rights reserved. Chapter 24 – Bonus Chapter: Introduction to Scripting with VBScript ® Outline 24.1 Introduction 24.2 Operators.

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

ISOM3230 Business Applications Programming
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 24 - VBScript Outline 24.1 Introduction 24.2 Operators 24.3 Data Types and Control Structures.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
The Web Warrior Guide to Web Design Technologies
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Introduction to Scripting.
1 Outline 13.1Introduction 13.2A Simple Program: Printing a Line of Text in a Web Page 13.3Another JavaScript Program: Adding Integers 13.4Memory Concepts.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Control Structures: Part 2. Introduction Essentials of Counter-Controlled Repetition For / Next Repetition Structure Examples Using the For / Next Structure.
Pertemuan 8 Introduction to Dynamic Web Programming Matakuliah: T0053/Web Programming Tahun: 2006 Versi: 2.
JavaScript, Third Edition
XP Tutorial 1 New Perspectives on JavaScript, Comprehensive1 Introducing JavaScript Hiding Addresses from Spammers.
Programming Concepts MIT - AITI. Variables l A variable is a name associated with a piece of data l Variables allow you to store and manipulate data in.
Introduction to scripting
 2004 Prentice Hall, Inc. All rights reserved. Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
 2004 Prentice Hall, Inc. All rights reserved. 1 Chapter 32 - VBScript Outline 32.1 Introduction 32.2 Operators 32.3 Data Types and Control Structures.
1 Dynamic HTML Client-Side Scripting with VBScript.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 22 – Dynamic HTML: Client- Side Scripting with VBScript Outline 22.1Introduction 22.2Operators.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
CMPS 211 JavaScript Topic 1 JavaScript Syntax. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction.
Using Client-Side Scripts to Enhance Web Applications 1.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
Arrays and 2D Arrays.  A Variable Array stores a set of variables that each have the same name and are all of the same type.  Member/Element – variable.
EIW - ASP Introduction1 Active Server Pages VBScript.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
 2000 Deitel & Associates, Inc. All rights reserved. Outline 8.1Introduction 8.2A Simple Program: Printing a Line of Text in a Web Page 8.3Another JavaScript.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Copyright © 2001 by Wiley. All rights reserved. Chapter 6: Using Arrays Control Arrays List Arrays Finding Items in Arrays Multiple Forms 2-Dimensional.
1 Scripting Languages VBScript - Recognized mainly by Internet Explorer only - Netscape does have a plug-in JavaScript - Recognized by Internet Explorer.
Visual Basic Programming I 56:150 Information System Design.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Part:2.  Keywords are words with special meaning in JavaScript  Keyword var ◦ Used to declare the names of variables ◦ A variable is a location in the.
 2003 Prentice Hall, Inc. All rights reserved. Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 3 – Introduction to C# Programming Outline 3.1 Introduction 3.2 Simple Program: Printing a Line.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Chapter 4 Getting Started with VBA. Subroutines Subroutine is the logical section of code that performs a particular task. Subroutine is also called a.
5.1 Introduction Problem Solving –Requires understanding of: Building blocks Program-construction principles BZUPAGES.COM.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
 2002 Prentice Hall. All rights reserved. 1 Chapter 5 – Control Structures: Part 2 Outline 5.1Introduction 5.2 Essentials of Counter-Controlled Repetition.
REEM ALMOTIRI Information Technology Department Majmaah University.
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Chapter 6 JavaScript: Introduction to Scripting
Visual Basic 6 (VB6) Data Types, And Operators
Client-Side Scripting with VBScript
Introduction to Scripting
Variables and Arithmetic Operations
Chapter 6 Variables What is VBScript?
Chapter 8 JavaScript: Control Statements, Part 2
Chapter 24 - VBScript Outline 24.1 Introduction 24.2 Operators
WEB PROGRAMMING JavaScript.
PHP.
VBScript Outline 32.1 Introduction 32.2 Operators
Hammad Lari Computer Science Department
JavaScript: Introduction to Scripting
Quick Test Professional Training Part 1
Presentation transcript:

 2001 Prentice Hall, Inc. All rights reserved. Chapter 24 – Bonus Chapter: Introduction to Scripting with VBScript ® Outline 24.1 Introduction 24.2 Operators 24.3 Data Types and Control Structures 24.4 VBScript Functions 24.5 VBScript Example Programs 24.6 Arrays 24.7 String Manipulation

 2001 Prentice Hall, Inc. All rights reserved Introduction Visual Basic Script (VBScript) –Subset of Microsoft Visual Basic –IE contains VBScript scripting engine (interpreter) –Similar to JavaScript JavaScript used more for client-side scripting –VBScript de facto language for ASP (Active Server Pages)

 2001 Prentice Hall, Inc. All rights reserved Operators VBScript –Not case-sensitive –Provides arithmetic operators, logical operators, concatenation operators, comparison operators and relational operators –Arithmetic operators Similar to JavaScript arithmetic operators Division operator –\ –Returns integer result Exponentiation operator –^ –Raises a value to a power

 2001 Prentice Hall, Inc. All rights reserved Operators

 2001 Prentice Hall, Inc. All rights reserved Operators

 2001 Prentice Hall, Inc. All rights reserved Operators –Comparison operators Only symbols for equality operator ( = ) and inequality operator ( <> ) differ from JavaScript Can also be used to compare strings –Logical operators And (logical AND) Or (logical OR) Not (logical negation) Imp (logical implication) Xor (exclusive OR) Eqv (logical equivalence) Not short-circuit; both conditions always evaluated

 2001 Prentice Hall, Inc. All rights reserved Operators

 2001 Prentice Hall, Inc. All rights reserved Operators String concatenation –Plus sign, + –Ampersand, & Formally called string concatenation operator –If both operands are strings, + and & can be used interchangeably s3 = s1 & s2 s3 = s1 + s2 –If varying data types, use ampersand ( & ) Error: s1 = “hello” + 22

 2001 Prentice Hall, Inc. All rights reserved Data Types and Control Structures VBScript has only one data type: –Variant Capable of storing different types of data –Variant subtypes Variable names –Cannot be keywords –Must begin with a letter –Max length: 255 characters –Letters, digits (0-9) and underscores OptionExplicit statement –Requires variables to be declared before use

 2001 Prentice Hall, Inc. All rights reserved Data Types and Control Structures

 2001 Prentice Hall, Inc. All rights reserved Data Types and Control Structures VBScript control structures –Every control structure begins and ends with one or more keywords (not curly braces as in JavaScript) –VBScript does not use statement terminator JavaScript uses semicolons –Parentheses around conditions optional –True : variant subtype boolean True or considered non- zero –False : variant subtype boolean False or considered 0

 2001 Prentice Hall, Inc. All rights reserved Data Types and Control Structures

 2001 Prentice Hall, Inc. All rights reserved Data Types and Control Structures

 2001 Prentice Hall, Inc. All rights reserved Data Types and Control Structures

 2001 Prentice Hall, Inc. All rights reserved Data Types and Control Structures 1 ’ VBScript 2 For y = 2 To 20 Step 2 3 Call MsgBox( "y = " & y ) 4 Next Fig Using keyword Step in VBScript’s For repetition structure. –Select Case/End Select Does not require break type statement –VBScript structures without direct JavaScript equivalents: Do Until/Loop Do/Loop Until Loop until condition becomes True

 2001 Prentice Hall, Inc. All rights reserved Data Types and Control Structures –Exit Do Immediate exit from Do While/Loop, Do/Loop While, Do Until/Loop or Do/Loop Until –Exit For Immediate exit from For/Next –For loop Optional Step keyword to increment or decrement

 2001 Prentice Hall, Inc. All rights reserved VBScript Functions Predefined functions –Variant functions IsEmpty –Returns True if variant not initialized –Math functions Cos, Sin, etc. –Take arguments in radians –radians = degrees  π/180 –InputBox Displays dialog in which user can input data –MsgBox Displays message dialog –VBScript functions often take optional arguments –Formatting functions FormatCurrency, FormatDateTime, etc.

 2001 Prentice Hall, Inc. All rights reserved VBScript Functions –Functions for getting info about scripting engine ScriptEngine –Returns “ Jscript ”, “ VBScript ” or “ VBA ” ScriptEngineBuildVersion –Returns current build version; ID number for current release ScriptEngineMajorVersion –Returns major version number for script engine ScriptEngineMinorVersion –Returns minor release number Line continuation character –Underscore character, _ –Statements cannot extend beyond current line without character

 2001 Prentice Hall, Inc. All rights reserved VBScript Functions

 2001 Prentice Hall, Inc. All rights reserved VBScript Functions

 2001 Prentice Hall, Inc. All rights reserved VBScript Functions

 2001 Prentice Hall, Inc. All rights reserved VBScript Example Programs tag –Used to set the language of an HTML document Option Explicit –Forces all variables to be declared Procedures –VBScript’s equivalent of a function in JavaScript –Sub Procedure that does not return value Ended with End Sub Const –Used to create constants

 2001 Prentice Hall, Inc. All rights reserved VBScript Functions

 2001 Prentice Hall, Inc. All rights reserved VBScript Functions

 2001 Prentice Hall, Inc. All rights reserved. Outline Our first VBScript Click the button to add an integer to the total addition.html Adding integers on a Web page using VBScript. Option Explicit designates that all variables must be named by the programmer OnClick function executes when user clicks the button cmdAdd Cint converts input from a string subtype to an integer subtype.

 2001 Prentice Hall, Inc. All rights reserved. Outline addition.html Adding integers on a Web page using VBScript. Message dialog

 2001 Prentice Hall, Inc. All rights reserved VBScript Example Programs tag’s attributes –for attribute Indicates the HTML component on which the script operates –event attribute Indicates the event to which the script should respond –language attribute Specifies the scripting language

 2001 Prentice Hall, Inc. All rights reserved. Outline Select a site to browse Select a site to browse Deitel & Associates, Inc Prentice Hall Prentice Hall Interactive site.html Using VBScript code to respond to an event. Creates a pull-down menu within the form

 2001 Prentice Hall, Inc. All rights reserved. Outline site.html Using VBScript code to respond to an event. Output Script response to user’s selecting an option in the menu.

 2001 Prentice Hall, Inc. All rights reserved VBScript Example Programs Procedures in the next program –Minimum Determines the smallest of three numbers –OddEven Determines if the smallest number is odd or even Comments –Indicated by either single quote ( ‘ ) or keyword Rem

 2001 Prentice Hall, Inc. All rights reserved. Outline Using VBScript Procedures <!-- 10 Option Explicit ' Find the minimum value. Assume that first value is 13 ' the smallest. 14 Function Minimum( min, a, b ) If a < min Then 17 min = a 18 End If If b < min Then 21 min = b 22 End If Minimum = min ' Return value 25 End Function Sub OddEven( n ) 28 If n Mod 2 = 0 Then 29 Call MsgBox( n & " is the smallest and is even" ) 30 Else 31 Call MsgBox( n & " is the smallest and is odd" ) 32 End If 33 End Sub Sub cmdButton_OnClick() minimum.html Program that determines the smallest of three numbers. Defines function minimum Defines subroutine OddEven Modulus operator determines whether number is odd or even

 2001 Prentice Hall, Inc. All rights reserved. Outline 36 Dim number1, number2, number3, smallest ' Convert each input to Long subtype 39 number1 = CLng( Document.Forms( 0 ).txtBox1.Value ) 40 number2 = CLng( Document.Forms( 0 ).txtBox2.Value ) 41 number3 = CLng( Document.Forms( 0 ).txtBox3.Value ) smallest = Minimum( number1, number2, number3 ) 44 Call OddEven( smallest ) 45 End Sub 46 --> Enter a number Enter a number Enter a number minimum.html Program that determines the smallest of three numbers.

 2001 Prentice Hall, Inc. All rights reserved. Outline minimum.html Program that determines the smallest of three numbers.

 2001 Prentice Hall, Inc. All rights reserved Arrays Arrays –Data structures of related items of same type –Fixed-size array Size does not change during program execution –Dynamic array Size can change during program execution Redimmable array (re-dimensionable array) –Array elements referred to by array name followed by element position (index) in parentheses, () –First array element at index 0 –Upper bound Highest valid index

 2001 Prentice Hall, Inc. All rights reserved Arrays Ubound function –Returns upper bound Procedures are Public by default –Accessible to scripts on other Web pages –Private  accessible only from HTML document in which defined ReDim function –Allocations memory for dynamic array –Keyword Preserve maintains current values in array –Memory for dynamic array can be deallocated using keyword Erase Multidimensional arrays –tripleArray(100, 8, 15) –Wrong: tripleArray(100)(8)(15)

 2001 Prentice Hall, Inc. All rights reserved. Outline Using VBScript Arrays " ) 21 End Sub Dim fixedSize( 3 ), fixedArray, dynamic(), k ReDim dynamic( 3 ) ' Dynamically size array 26 fixedArray = Array( "A", "B", "C" ) ' Populate arrays with values 29 For k = 0 to UBound( fixedSize ) 30 fixedSize( k ) = 50 - k 31 dynamic( k ) = Chr( 75 + k ) 32 Next ' Display contents of arrays 35 Call DisplayArray( fixedSize, "fixedSize" ) arrays.html Using VBScript arrays. Defines subroutine DisplayArray Initializes arrays

 2001 Prentice Hall, Inc. All rights reserved. Outline 36 Call DisplayArray( fixedArray, "fixedArray" ) 37 Call DisplayArray( dynamic, "dynamic" ) ' Resize dynamic, preserve current values 40 ReDim Preserve dynamic( 5 ) 41 dynamic( 3 ) = dynamic( 4 ) = Call DisplayArray( dynamic, _ 45 "dynamic after ReDim Preserve" ) 46 --> arrays.html Using VBScript arrays.

 2001 Prentice Hall, Inc. All rights reserved String Manipulation VBScript strings –Case sensitive String-manipulation functions –List of all String-manipulation functions in Fig on pages in the textbook –Instr Searches string (first argument) for substring (second argument) Searching performed from left to right If substring is found, index of found substring in the search string returned Instr("sparrow","arrow") returns 3 Instr("japan","wax") returns 0

 2001 Prentice Hall, Inc. All rights reserved String Manipulation –Lcase Returns a lowercase string returns –Right Returns string containing characters from right side of string argument Right(“Web”,2) returns “eb” –Join Returns string containing the concatenation of array elements separated by a delimiter Default delimiter is a space –Change by passing a delimiter string for second argument Join(Array("one","two","three")) returns “one two three” Join(Array("one","two","three"),"$^") returns “one$^two$^three”

 2001 Prentice Hall, Inc. All rights reserved String Manipulation –Split Returns array containing substrings Default delimiter is space character Optional second argument changes the delimiter Split("red,white,and blue", ",") returns array containing elements "red", "white" and "and blue"

 2001 Prentice Hall, Inc. All rights reserved String Manipulation

 2001 Prentice Hall, Inc. All rights reserved String Manipulation

 2001 Prentice Hall, Inc. All rights reserved String Manipulation

 2001 Prentice Hall, Inc. All rights reserved String Manipulation Pig Latin translation algorithm: –Translate one word at a time –If first letter a consonant, Move first letter to end of word Add " ay" jump becomes umpjay –If first letter a vowel Move first letter to end of word Add "y" ace becomes ceay –Blanks remain as blanks –Assume no punctuation marks, all words have two or more letters

 2001 Prentice Hall, Inc. All rights reserved. Outline Using VBScript String Functions <!-- 10 Option Explicit Public Function TranslateToPigLatin( englishPhrase ) 13 Dim words ' Stores each individual word 14 Dim k, suffix ' Get each word and store in words the 17 ' default delimiter for Split is a space 18 words = Split( englishPhrase ) For k = 0 to UBound( words ) 21 ' Check if first letter is a vowel 22 If InStr( 1, "aeiou", _ 23 LCase( Left( words( k ), 1 ) ) ) Then 24 suffix = "y" 25 Else 26 suffix = "ay" 27 End If ' Convert the word to pig Latin 30 words( k ) = Right( words( k ), _ 31 Len( words( k ) ) - 1 ) & _ 32 Left( words( k ), 1 ) & suffix 33 Next ' Return translated phrase, each word piglatin.html Using VBScript string- processing functions. Defines Function TranslateToPigLatinSplit s words typed in by user Converts each word into pig Latin

 2001 Prentice Hall, Inc. All rights reserved. Outline 36 ' is separated by spaces 37 TranslateToPigLatin = Join( words ) 38 End Function Sub cmdButton_OnClick() 41 Dim phrase phrase = Document.Forms( 0 ).txtInput.Value Document.forms( 0 ).txtPigLatin.Value = _ 46 TranslateToPigLatin( phrase ) 47 End Sub 48 --> Enter a sentence Pig Latin piglatin.html Using VBScript string- processing functions. Join function returns “translated” phrase

 2001 Prentice Hall, Inc. All rights reserved. Outline piglatin.html Using VBScript string- processing functions. Output