Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 19

Scripting Languages -

VBScript
Compiled Languages
 Source File (Text)
 Pre-process – Replace/update directives
 Compile – Create assembly language file
 Compilers and machine specific
 Once compiled, cannot be decompiled (easily) – Not 1-to-1
 Assemble – Create binary executable
 Advantages
 Fast!
 (Relatively) Safe from alteration/theft
 Use traditional languages (smaller learning curve, lots of
talent available)
 Disadvantages
 Not portable
 Need to re-compile to change
 Not efficient for simple tasks
Scripting Languages Background
 Unix Shell scripts – sh, csh, bash, tcsh, zsh,
ksh
 Allowed easier performance of basic system tasks
 Text commands could be “processed”
 Same concept as batch files
 Standalone scripting languages
 Awk, sed, grep, etc…
 Allowed limited power to do repetitive tasks easy
 Made for specific-purpose
Scripting Languages - General
 TCL/TK
 Python
 PERL
 Used for more advanced programming tasks
 Became almost as powerful as any compiled language
 Advantages
 Text files – can be ported anywhere!
 Easy to change
 Easy to write/debug
 Disadvantages
 Slow – must be interpreted by a script interpreter (not standalone)
 Not quite as powerful as compiled languages (e.g. for addressing of
hardware)
Scripting Languages – Web Based
 Originally PERL was most popular through CGI
 PERL had issues
 Slow
 Required a new instance of the PERL interpreter to
spawn with each request
 Somewhat convoluted to learn – based on C/C+
+/Unix scripting
 Interpreter support was scattered
 Not built specifically for the web
 Only Server Side
 PERLEXAMPLE1
Web Scripting – JavaScript History
 ~1994 Netscape begins building LiveScript!
 Netscape forms alliance with Sun, gains naming rights to
Java name
 Renames LiveScript Javascript, and releases with
browser 2.0
 Microsoft responds with VBScript
 Microsoft response with Jscript
 Netscape fires back with 1.1, 1.2 versions
 ECMA – European Computer Manufacturers Association
– creates non-partisan standard
 Javascript designed for client-side scripting
 Netscape had >50% of the market
 JSEXAMPLE1
Web Scripting – VBScript History
 Visual Basic
 Created as a simple alternative to C/C++ development
 Supported RAD within Windows
 Based on BASIC programming language
 Contained and IDE, support for GUI tools for display
 Became overnight success
 Visual Basic for Applications
 Subset of Visual Basic
 Created to extend other programs (e.g. Office)
 Used standard VB commands
 Adopted by other companies to customize their applications
(Siebel, Clarify)
Web Scripting – VBScript History,
cont’d
 Visual Basic Scripting Edition
 Created as a “safer” version of VBA
 Strict subset of VBA
 Made in response to Javascript
 Supported in Internet Explorer 3.x+
 Easier to learn, based on familiar VB/BASIC
commands
 Originally client side
 No file reads/writes/OS manipulation like VBA
 Expanded to Server side
 Expanded to Outlook
 Problem .vbs extensions!
Web Scripting – VBScript History,
cont’d
 Expanded to support ASP pages (server
side!)
 Allowed dynamic SQL queries
 Allowed better SSI
 Could actually do real-time calculations
 Removed the limitations of PERL
 Still a bit slow, interpreted, and not quite as
robust as VB
VBScript Basics
 <script> tag
 delineates scripting language code will follow
 Attributes
 type=“text/vbscript”
 language=”vbscript” or “vbs”
 runat = “server” (default is browser)
 VBScript is Case insensitive
 Whitespace is ignored
 Comments should use ‘ or Rem
 Code is denoted by lines. To span multiple lines, use _
 Code outside of a subroutine or function automatically
runs on page load
 VBEXAMPLE1
VBScript Basics – Data Types
 Only one main type – Variant
 Similar to variable in other languages
 No specific datatype (e.g. integer, real,
character, string, etc…)
 Global or local scope
 Declared using the Dim statement
 Dim var1, var2, var3
 var = 0
 var = “Hello World”
VBScript Basics – Data Subtypes
 Controlled by VBScript engine
 0 -Empty – Declared, but no value is assigned
 1 -Null – Contains no valid data
 Var = NULL
 11 - Boolean
 Var1 = True
 17 - Byte – 0 – 255
 2 - Integer - -32,768 – 32767
 3 - Long - -2,000,000,000 – 2,000,000,000
 4,5 - Single, Double – Real numbers (decimals!)
 7 - Date/Time – 01/01/100 – 12/31/9999
 6 - Currency
 8 - String
 9 - Object – HTML or ActiveX
 10 - Error
VBScript Basics – Variable
Operations
 Determining the variable subtype
 VarType (var1)
 Returns numeric representation of the datatype
 TypeName (var1)
 Returns actual name of type!
 VBScript can perform operations on two variants without needing
you to make the types agree
 Var1 = 7
 Var2 = 123.23
 Var3 = Var1 + Var2
 Constants
 Const PI 3.14
 Usually capitalized
 Cannot be changed
 VBEXAMPLE2
VBScript Basics – Math Operators
 + addition
 var1 = var2 + var3
 – subtraction
 var1 = var2 – var3
 / division
 var1 = var2 / var3
 * multiplication
 var1 = var2 * var3
 \ Integer division
 var1 = var2 \ var3
 Returns only the integer portion
 Mod – modulo
 Var1 = var2 Mod var3
 Returns the remainder after division
 ^ - Exponentiation
 var1 = var2 ^ var3
VBScript Basics – Logical
Operators
 Concatenation - &
 “Adds” strings together
 Comparison
 >, <, <>, >=, <=, =
 Returns a “True” or a “False”
 E.g. var1 > 6
 Logical
 AND, Or, Not
 VBEXAMPLE3
VBScript Basics – Control
Statements – If-Then-Else
 Determine program flow
 Conditional statements
 If – Then
 If var1 > 2 Then
 Document.Write “var1 >2”
 End If
 If – Then – Else
 If var1 > 2 Then
 Document.Write “var1 >2”
 Else
 Document.Write “var1 <=2”
 End If
VBScript Basics – Control
Statements – If-Then-ElseIf
 If – Then – ElseIf
 Same as nested If’s
 If var1 > 2 Then
 Document.Write “var1 >2”
 ElseIf var1 = 2 Then
 Document.Write “var1 = 2”
 Else
 Document.Write “var1 < 2”
 End If
 VBEXAMPLE4
VBScript Basics – Control
Statements – Select-Case
 Concise way of writing multiple if-then statements
 Select Case name
 Case “Bob”
 Document.Write “Bob”
 Case “Mary”
 Document.Write “Mary”
 Case “Bill”
 Document.Write “Bill”
 Case Else
 Document.Write “Other case!”
 End Select
 VBEXAMPLE5
VBScript Basics – Looping
 Repeats a command or set of commands
 For – Next
 For x = 1 to 20
 Document.Write “<br />” & x
 Next
 VBEXAMPLE6

You might also like