 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.

Slides:



Advertisements
Similar presentations
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
Advertisements

 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.
JavaScript Part for Repetition Statement for statement Cpecifies each of the items needed for counter-controlled repetition with a control variable.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Introduction to Scripting.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Pertemuan 8 Introduction to Dynamic Web Programming Matakuliah: T0053/Web Programming Tahun: 2006 Versi: 2.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Functions Part I.
Tutorial 14 Working with Forms and Regular Expressions.
Introduction to C Programming
Arrays Array of Controls: several controls, of the same type (Class: a prototype for an object indicating the properties and methods), that have the same.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements II.
 2004 Prentice Hall, Inc. All rights reserved. 1 Chapter 10 - JavaScript: Functions Outline 10.1 Introduction 10.2 Program Modules in JavaScript 10.3.
Introduction to scripting
1 JavaScript: Functions and Arrays October 18, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel, Deitel,
Using Data Active Server Pages Objectives In this chapter, you will: Learn about variables and constants Explore application and session variables Learn.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
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.
IE 212: Computational Methods for Industrial Engineering
 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. Chapter 24 – Bonus Chapter: Introduction to Scripting with VBScript ® Outline 24.1 Introduction 24.2 Operators.
 2004 Prentice Hall, Inc. All rights reserved. 1 Chapter 11 - JavaScript: Arrays Outline 11.1 Introduction 11.2 Arrays 11.3 Declaring and Allocating Arrays.
Database-Driven Web Sites, Second Edition1 Chapter 3 INTRODUCTION TO CLIENT-SIDE SCRIPTS.
CSS Class 7 Add JavaScript to your page Add event handlers Validate a form Open a new window Hide and show elements Swap images Debug JavaScript.
 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.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Arrays.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Java Script: Arrays (Chapter 11 in [2]). 2 Outline Introduction Introduction Arrays Arrays Declaring and Allocating Arrays Declaring and Allocating Arrays.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
Dr. Qusai Abuein1 Internet & WWW How to program Chap.(6) JavaScript:Introduction to Scripting.
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
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.
JavaScript, Fourth Edition
Copyright © 2001 by Wiley. All rights reserved. Chapter 6: Using Arrays Control Arrays List Arrays Finding Items in Arrays Multiple Forms 2-Dimensional.
6-1 Chapter 6 Working with Arrays in VB.NET. 6-2 Learning Objectives Understand the use of list and table arrays in VB.NET projects and the difference.
1 Scripting Languages VBScript - Recognized mainly by Internet Explorer only - Netscape does have a plug-in JavaScript - Recognized by Internet Explorer.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
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.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Arrays.
REEM ALMOTIRI Information Technology Department Majmaah University.
 2001 Prentice Hall, Inc. All rights reserved. Outline 1 JavaScript.
VBA - Excel VBA is Visual Basic for Applications
Chapter 6 JavaScript: Introduction to Scripting
Client-Side Scripting with VBScript
Introduction to Scripting
JavaScript: Functions.
Chapter 24 - VBScript Outline 24.1 Introduction 24.2 Operators
WEB PROGRAMMING JavaScript.
VBScript Outline 32.1 Introduction 32.2 Operators
Hammad Lari Computer Science Department
JavaScript: Introduction to Scripting
Introduction to Computer Programming IT-104
Presentation transcript:

 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 32.4 VBScript Functions 32.5 VBScript Example Programs 32.6 Arrays 32.7 String Manipulation 32.8 Classes and Objects 32.9 Operator Precedence Chart Web Resources

 2004 Prentice Hall, Inc. All rights reserved. 2 Objectives In this tutorial, you will learn: –To become familiar with the VBScript language. –To use VBScript keywords, operators and functions to write client-side scripts. –To be able to write Sub and Function procedures. –To use VBScript arrays and regular expressions. –To be able to write VBScript abstract data types called Classes. –To be able to create objects from Classes. –To be able to write Property Let, Property Get and Property Set procedures.

 2004 Prentice Hall, Inc. All rights reserved Introduction VBScript –Subset of Microsoft Visual Basic –Specific to Internet Explorer –JavaScript has replaced VBScript as standard –Most commonly used alongside ASP Active Server Pages

 2004 Prentice Hall, Inc. All rights reserved Operators Types of operators –Arithmetic Most are similar to JavaScript’s –Logical –Concatenation –Comparison –Relational VBScript is case-insensitive

 2004 Prentice Hall, Inc. All rights reserved Operators

 2004 Prentice Hall, Inc. All rights reserved Operators ≤ ≠

 2004 Prentice Hall, Inc. All rights reserved Operators

 2004 Prentice Hall, Inc. All rights reserved Operators String concatenation –& and + operators both perform concatenation –Always use & operator + will attempt addition if both operands are not strings

 2004 Prentice Hall, Inc. All rights reserved Data Types and Control Structures Variant type –Only data type –Many subtypes which mimic standard data types –VBScript treats each variable as the type of data it currently contains –Not necessary to declare a data type Variable names –Cannot be keywords –Must start with letter –Option Explicit Forces variables to be declared before use

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

 2004 Prentice Hall, Inc. All rights reserved Data Types and Control Structures Control structures –Begin and end with keywords Not braces, as in JavaScript –Statements end when line ends No semicolons –Parentheses optional

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

 2004 Prentice Hall, Inc. All rights reserved Data Types and Control Structures Multiple-selection –Elseif keyword Replaces if … else if … else statement of JavaScript –Select Case statement Replaces switch in JavaScript No break; statement Case Else replaces default case

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

 2004 Prentice Hall, Inc. All rights reserved Data Types and Control Structures Looping –While … Wend and Do While … Loop Analogous to JavaScript’s while statement –Do … Loop While Analogous to JavaScript’s do … while statement –Do … Until Loop and Do … Loop Until No direct equivalent in JavaScript Repeat until loop-continuation condition is true –For Condition cannot be modified mid-loop Optional Step keyword –Exit Do and Exit For Break out of loops

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

 2004 Prentice Hall, Inc. All rights reserved. Outline 17 For Loop Sample (1 of 1) For repetition statement with keyword Step

 2004 Prentice Hall, Inc. All rights reserved VBScript Functions Calling functions –Keyword Call –Line continuation character _ (underscore) Type functions –VBScript provides set of built-in functions –Many deal with determining subtype of Variant variable

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

 2004 Prentice Hall, Inc. All rights reserved VBScript Functions Math functions –VBScript provides many functions for common operations Exponential Logarithmic Square root Rounding Absolute value Trigonometry Random number generation

 2004 Prentice Hall, Inc. All rights reserved VBScript Functions ≤

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

 2004 Prentice Hall, Inc. All rights reserved VBScript Functions Formatting functions –Currency –Dates and times –Numbers –Percentages

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

 2004 Prentice Hall, Inc. All rights reserved. 25 Informational functions –ScriptEngine –ScriptEngineBuildVersion –ScriptEngineMajorVersion –ScriptEngineMinorVersion –Example: –Returns: "VBScript, 5207, 5, 5" 32.4 VBScript Functions ScriptEngine() & ", " & ScriptEngineBuildVersion() & ", " _ & ScriptEngineMajorVersion() & ", " & _ ScriptEngineMinorVersion()

 2004 Prentice Hall, Inc. All rights reserved. 26 User interaction –InputBox Displays dialog that accepts input intValue = InputBox( "Enter an integer", "Input Box",, 1000, 1000 ) –MsgBox Displays message dialog Customizable buttons and icon Call MsgBox( "VBScript is fun!",, "Results" ) 32.4 VBScript Functions

 2004 Prentice Hall, Inc. All rights reserved. 27 Example using addition – tag type attribute text/vbscript –Enclose code in XHTML comments Keep incompatible browsers from displaying as test –OnClick –Local variables Only exist inside procedure where declared –Event procedures –CInt –Constants 32.5 VBScript Example Programs

 2004 Prentice Hall, Inc. All rights reserved. Outline 28 addition.html (1 of 2) Set type to VBScript. Option Explicit statement.

 2004 Prentice Hall, Inc. All rights reserved. Outline 29 addition.html (2 of 2) Define procedure OnClick for the cmdAdd button. Use CInt to convert input values from string subtype to integer subtype.

 2004 Prentice Hall, Inc. All rights reserved VBScript Example Programs Fig Adding integers on a Web page using VBScript.

 2004 Prentice Hall, Inc. All rights reserved. 31 Example of redirection –Send browser to a different URL Location property –for attribute –OnChange event –Accessing properties SiteSelector.value 32.5 VBScript Example Programs

 2004 Prentice Hall, Inc. All rights reserved. Outline 32 site.html (1 of 2) Create form with select component.

 2004 Prentice Hall, Inc. All rights reserved. Outline 33 site.html (2 of 2) Script response to user’s selecting an option in the menu The tag’s for attribute indicates the XHTML component on which the script operates ( SiteSelector ). The event attribute indicates the event to which the script responds ( OnChange ).

 2004 Prentice Hall, Inc. All rights reserved VBScript Example Programs Fig Using VBScript code to respond to an event (Courtesy of Prentice Hall, Inc.)

 2004 Prentice Hall, Inc. All rights reserved. 35 Comments –‘ and keyword Rem –‘ character is preferred style Programmer-defined procedures –Keywords Function, Sub, End Sub and End Function –Returning values Variable with same name as procedure –Place in page head section so all scripts can access them –Keywords Exit Function and Exit Sub 32.5 VBScript Example Programs

 2004 Prentice Hall, Inc. All rights reserved. Outline 36 minimum.html (1 of 3) Define procedure Minimum.

 2004 Prentice Hall, Inc. All rights reserved. Outline 37 minimum.html (2 of 3) Use modulus operator to determine whether number odd or even. Single-line comment. Define an event procedure for handling cmdButton ’s OnClick event. Pass the smallest number to procedure OddEven. Call function Minimum.

 2004 Prentice Hall, Inc. All rights reserved. Outline 38 minimum.html (3 of 3)

 2004 Prentice Hall, Inc. All rights reserved VBScript Example Programs Fig Program that determines the smallest of three numbers.

 2004 Prentice Hall, Inc. All rights reserved. 40 Arrays –Related data items of same type –Fixed size or dynamic Also “redimmable” –Made up of individual elements Accessed via array name, parentheses and index number Start at position zero Declaring arrays –Keyword Dim –Name –Highest valid index Upper bound 32.6 Arrays

 2004 Prentice Hall, Inc. All rights reserved. 41 Examples –Declaring array with three elements Dim numbers( 2 ) –Assigning values to each element numbers(0) = 77 numbers(1) = 68 numbers(2) = Arrays

 2004 Prentice Hall, Inc. All rights reserved. 42 Examples, cont. –Declaring array and using For loop to fill with values Fills with multiples of 3 from 0 through 30 Dim h( 11 ), x, i i = 0 For x = 0 To 30 Step 3 h(i) = CInt( x ) i = CInt( i ) + 1 Next 32.6 Arrays

 2004 Prentice Hall, Inc. All rights reserved. 43 Array dimensions –UBound and LBound functions LBound is always zero Access modifiers –Public vs. Private Public default Dynamic arrays –Keyword ReDim Keyword Preserve Allocating arrays larger than original vs. smaller than original –Keyword Erase 32.6 Arrays

 2004 Prentice Hall, Inc. All rights reserved. Outline 44 arrays.html (1 of 3) Define procedure DisplayArray.Function UBound returns the upper bound (i.e., the highest-numbered index).

 2004 Prentice Hall, Inc. All rights reserved. Outline 45 arrays.html (2 of 3) Statement ReDim allocates memory for array dynamic. Function Array takes any number of arguments and returns an array containing those arguments. Initialize arrays.

 2004 Prentice Hall, Inc. All rights reserved. Outline 46 arrays.html (3 of 3) Call procedure DisplayArray. Reallocate dynamic ’s memory to 5 elements. Keyword Preserve, when used with ReDim, maintains the current values in the array.

 2004 Prentice Hall, Inc. All rights reserved VBScript Example Programs Fig Using VBScript arrays.

 2004 Prentice Hall, Inc. All rights reserved. 48 Multidimensional arrays –Like normal arrays Rows and columns rather than just columns –UBound and LBound still work Dimension is second argument –Can be fixed size or created dynamically 32.6 Arrays

 2004 Prentice Hall, Inc. All rights reserved. 49 Examples of multidimensional arrays –Declaring two- and three-dimensional arrays Dim b(2, 2), tripleArray(100, 8, 15) –Determining upper bound of third dimension For x = 0 To UBound(tripleArray, 3) –Dynamically allocating three-dimensional array ReDim threeD(11, 8, 1) 32.6 Arrays

 2004 Prentice Hall, Inc. All rights reserved. 50 Strings –Case sensitive in VBScript –Most string manipulation functions do not modify original Return new string with modifications 32.7 String Manipulation

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

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

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

 2004 Prentice Hall, Inc. All rights reserved. 54 Translating to Pig Latin –Uses string methods Split InStr LCase Left 32.7 String Manipulation

 2004 Prentice Hall, Inc. All rights reserved. Outline 55 piglatin.html (1 of 3) Define Function procedure TranslateToPigLatin Split phrase into words

 2004 Prentice Hall, Inc. All rights reserved. Outline 56 piglatin.html (2 of 3) Convert each word to pig Latin Function InStr searches a string for a substring. Function LCase returns a lowercase string. Return translated phrase using Join function Function Right returns a string containing characters from the right side of a string argument. Function Len returns the number of characters in a string. Function Left returns a string containing characters from the left side of a string argument.

 2004 Prentice Hall, Inc. All rights reserved. Outline 57 piglatin.html (3 of 3) Define an event procedure for cmdButton ’s OnClick event.

 2004 Prentice Hall, Inc. All rights reserved String Manipulation Fig Using VBScript string-processing functions.

 2004 Prentice Hall, Inc. All rights reserved. 59 Object-based programming –Objects have data and behavior –Information hiding Not necessary to know internal details to use class Allows class internals to be replaced/upgraded without breaking code that uses class –Objects model real-world entities Makes programs easier to understand –Promotes reusability –Objects are instances of classes Class can have many objects existing at same time 32.8 Classes and Objects

 2004 Prentice Hall, Inc. All rights reserved. 60 Objects in VBScript –Keyword Class –Methods Procedures that belong to class –Instance variables Exist only inside class 32.8 Classes and Objects

 2004 Prentice Hall, Inc. All rights reserved. 61 Abstract data-types –Powerful feature for simplifying programs –Represented as classes –Describe data in terms of behavior –Instance variables should be Private Allow access through methods Ensure integrity and consistency Property Let, Property Get, Property Set Exit Property 32.8 Classes and Objects

 2004 Prentice Hall, Inc. All rights reserved. Outline 62 Property Let Sample (1 of 1) A simple Property Let procedure

 2004 Prentice Hall, Inc. All rights reserved. Outline 63 Property Let Sample (1 of 1) A simple Property Get procedure

 2004 Prentice Hall, Inc. All rights reserved. Outline 64 Class Definition Sample (1 of 1) A simple Class definition

 2004 Prentice Hall, Inc. All rights reserved. 65 Property Set –Use for basic Variant sub-type variables Public Property Set BirthDay(bDay) Set mBirthDate = bDay End Property Public Property Get BirthDay() Set BirthDay = mBirthDate End Property 32.8 Classes and Objects

 2004 Prentice Hall, Inc. All rights reserved. 66 Regular expressions in VBScript –Pattern matching –Class RegExp Pattern property Test method –^ character Beginning of string –\d Digits –{ } Exactly this many occurrences 32.8 Classes and Objects

 2004 Prentice Hall, Inc. All rights reserved. 67 Regular expressions in VBScript, cont. –$ character End of string –Literal characters Simplifying properties –Keywords With…End With Reduces amount of typing 32.8 Classes and Objects

 2004 Prentice Hall, Inc. All rights reserved. Outline 68 classes.html (1 of 5) Define Class PersonDefine Property Let and Property Get procedures

 2004 Prentice Hall, Inc. All rights reserved. Outline 69 classes.html (2 of 5) Define Property Let SocialSecurityNumber Call function Validate

 2004 Prentice Hall, Inc. All rights reserved. Outline 70 classes.html (3 of 5) Define Function Validate Use regular expression to check format Define Function ToString.

 2004 Prentice Hall, Inc. All rights reserved. Outline 71 classes.html (4 of 5) Instantiate Person object. Provide an event procedure for cmdButton ’s OnClick event. Use the With … End With statement to set several property values for p and call p ’s ToString method.

 2004 Prentice Hall, Inc. All rights reserved. Outline 72 classes.html (5 of 5)

 2004 Prentice Hall, Inc. All rights reserved Classes and Objects Fig Using VBScript classes and regular expressions.

 2004 Prentice Hall, Inc. All rights reserved Classes and Objects Fig Using VBScript classes and regular expressions.

 2004 Prentice Hall, Inc. All rights reserved Operator Precedence Chart