Scripting Languages
Scripting Languages
Scripting Languages
-Scripting Languages -
-
-VBScript
VBScript
VBScript
VBScript
Compiled Languages
Compiled Languages
Source File (Text)Source File (Text)
PrePre--pr pr ocessocess ±± Replace/update directivesReplace/update directives
CompileCompile ±± Create assembly language fileCreate assembly language file
Compilers and machine specificCompilers and machine specific
Once compiled, cannot be decompiled (easily)Once compiled, cannot be decompiled (easily) ±± Not 1Not 1--toto--11
AssembleAssemble ±± Create binary executableCreate binary executable
AdvantagesAdvantages
Fast!Fast!
(Relatively) Safe fr (Relatively) Safe fr om alteration/theftom alteration/theft
Use traditional languages (smaller learning curve, lots of Use traditional languages (smaller learning curve, lots of
talent available) talent available)
DisadvantagesDisadvantages
Not portableNot portable
Need to reNeed to re--compile to changecompile to change
Scripting Languages Backgr
ound
Scripting Languages Backgr
ound
Unix Shell scripts
Unix Shell scripts ±
± sh, csh, bash, tcsh, zsh,
sh, csh, bash, tcsh, zsh,
ksh
ksh
Allowed easier perf Allowed easier perf or or mance of mance of basic system tasksbasic system tasks
Text commands could be ³pr Text commands could be ³pr ocessed´ocessed´
Same concept as batch filesSame concept as batch files
Standalone scripting languages
Standalone scripting languages
Awk, sed, grep, etc«Awk, sed, grep, etc«
Allowed limited power to do repetitive tasks easyAllowed limited power to do repetitive tasks easy
Scripting Languages
Scripting Languages -- General
General
TCL/TKTCL/TK PythonPython PERLPERL
Used f Used f or or more advanced pr more advanced pr ogramming tasksogramming tasks
Became almost as powerful as any compiled languageBecame almost as powerful as any compiled language
AdvantagesAdvantages
Text filesText files ±± can be ported anywhere!can be ported anywhere!
Easy to changeEasy to change
Easy to write/debugEasy to write/debug
DisadvantagesDisadvantages
SlowSlow ±± must be interpreted by a script interpreter (not standalone)must be interpreted by a script interpreter (not standalone)
Not quite as powerful as compiled languages (e.g. f Not quite as powerful as compiled languages (e.g. f or addressing of or addressing of hardware)
Scripting Languages
Scripting Languages ±
± Web Based
Web Based
Originally PERL was most popular thr
Originally PERL was most popular thr
ough CGI
ough CGI
PERL had issues
PERL had issues
SlowSlow
Required a new instance of the PERL interpreter toRequired a new instance of the PERL interpreter to
spawn with each request spawn with each request
Somewhat convoluted to learnSomewhat convoluted to learn ±± based onbased on
C/C++/Unix scripting C/C++/Unix scripting
Interpreter support was scatteredInterpreter support was scattered
Not built specifically f Not built specifically f or the webor the web
Only Server SideOnly Server Side
Web Scripting
Web Scripting ±
± JavaScript History
JavaScript History
~1994 Netscape begins building LiveScript!~1994 Netscape begins building LiveScript!
Netscape f Netscape f or or ms alliance with Sun, gains naming rights toms alliance with Sun, gains naming rights to
Java name Java name
Renames LiveScript Javascript, and releases withRenames LiveScript Javascript, and releases with
br owser 2.0 br owser 2.0
Micr Micr osoft responds with VBScriptosoft responds with VBScript
Micr Micr osoft response with Jscriptosoft response with Jscript
Netscape fires back with 1.1, 1.2 versionsNetscape fires back with 1.1, 1.2 versions
ECMAECMA ±± Eur Eur opean Computer Manufacturers Associationopean Computer Manufacturers Association
±
± creates noncreates non--partisan standardpartisan standard
Javascript designed f Javascript designed f or clientor client--side scriptingside scripting
Netscape had >50% of the marketNetscape had >50% of the market
Web Scripting
Web Scripting ±
± VBScript History
VBScript History
Visual BasicVisual Basic
Created as a simple alternative to C/C++ developmentCreated as a simple alternative to C/C++ development
Supported RAD within WindowsSupported RAD within Windows
Based on BASIC pr Based on BASIC pr ogramming languageogramming language
Contained and IDE, support f Contained and IDE, support f or GUI tools f or GUI tools f or displayor display
Became overnight successBecame overnight success
Visual Basic f Visual Basic f or Applicationsor Applications
Subset of Visual BasicSubset of Visual Basic
Created to extend other pr Created to extend other pr ograms (e.g. Office)ograms (e.g. Office)
Used standard VB commandsUsed standard VB commands
Adopted by other companies to customize their applicationsAdopted by other companies to customize their applications (Siebel, Clarify)
Web Scripting
Web Scripting ±
± VBScript History,
VBScript History,
cont¶d
cont¶d
Visual Basic Scripting Edition
Visual Basic Scripting Edition
Created as a ³safer´ version of VBACreated as a ³safer´ version of VBA
Strict subset of VBAStrict subset of VBA
Made in response to JavascriptMade in response to Javascript
Supported in Internet Explorer 3.x+Supported in Internet Explorer 3.x+
Easier to learn, based on familiar VB/BASICEasier to learn, based on familiar VB/BASIC
commands commands
Originally client sideOriginally client side
No file reads/writes/OS manipulation like VBANo file reads/writes/OS manipulation like VBA
Expanded to Server sideExpanded to Server side
Expanded to OutlookExpanded to Outlook
Web Scripting
Web Scripting ±
± VBScript History,
VBScript History,
cont¶d
cont¶d
Expanded to support ASP pages (server
Expanded to support ASP pages (server
side!)
side!)
Allowed dynamic SQL queries
Allowed dynamic SQL queries
Allowed better SSI
Allowed better SSI
Could actually do real
Could actually do real--time calculations
time calculations
Removed the limitations of PERL
Removed the limitations of PERL
Still a bit slow, interpreted, and not quite as
Still a bit slow, interpreted, and not quite as
r
obust as VB
VBScript Basics
VBScript Basics
<script> tag<script> tag
delineates scripting language code will f delineates scripting language code will f ollowollow AttributesAttributes type=³text/vbscript´type=³text/vbscript´ language=´vbscript´ or ³vbs´language=´vbscript´ or ³vbs´
runat = ³server´ (default is br runat = ³server´ (default is br owser)owser)
VBScript is Case insensitiveVBScript is Case insensitive
Whitespace is ignoredWhitespace is ignored
Comments should use µ or RemComments should use µ or Rem
Code is denoted by lines. TCode is denoted by lines. To span multiple lines, use _ o span multiple lines, use _
Code outside of a subr Code outside of a subr outine or function automaticallyoutine or function automatically
runs on page load runs on page load
VBScript Basics
VBScript Basics ±
± Data Types
Data Types
Only one main type
Only one main type ±
± Variant
Variant
Similar to variable in other languages
Similar to variable in other languages
No specific datatype (e.g. integer, real,
No specific datatype (e.g. integer, real,
character, string, etc«)
character, string, etc«)
Global or local scope
Global or local scope
Declared using the Dim statement
Declared using the Dim statement
Dim var1, var2, var3Dim var1, var2, var3
var = 0var = 0
VBScript Basics
VBScript Basics ±
± Data Subtypes
Data Subtypes
Contr Contr olled by VBScript engineolled by VBScript engine
00 --EmptyEmpty ±± Declared, but no value is assignedDeclared, but no value is assigned
11 --NullNull ±± Contains no valid dataContains no valid data
Var = NULLVar = NULL
1111 -- BooleanBoolean
Var1 = TrueVar1 = True
1717 -- ByteByte ±± 00 ±± 255255 22 -- Integer Integer -- --32,76832,768 ±± 3276732767 33 -- LongLong -- --2,000,000,0002,000,000,000 ±± 2,000,000,0002,000,000,000
4,54,5 -- Single, DoubleSingle, Double ±± Real numbers (decimals!)Real numbers (decimals!) 77 -- Date/TimeDate/Time ±± 01/01/10001/01/100 ±± 12/31/999912/31/9999 66 -- CurrencyCurrency 88 -- StringString
99 -- ObjectObject ±± HTML or ActiveXHTML or ActiveX
VBScript Basics
VBScript Basics ±
± Variable
Variable
Operations
Operations
Deter Deter mining the variable subtypemining the variable subtype
VarType (var1)VarType (var1)
Returns numeric representation of the datatypeReturns numeric representation of the datatype
TypeName (var1)TypeName (var1)
Returns actual name of type!Returns actual name of type!
VBScript can perf VBScript can perf or or m operations on two variants without needingm operations on two variants without needing
you to make the types agree you to make the types agree
Var1 = 7Var1 = 7
Var2 = 123.23Var2 = 123.23
Var3 = Var1 + Var2Var3 = Var1 + Var2
ConstantsConstants
Const PI 3.14Const PI 3.14
Usually capitalizedUsually capitalized
Cannot be changedCannot be changed
VBScript Basics
VBScript Basics ±
± Math Operators
Math Operators
+ addition+ addition
var1 = var2 + var3var1 = var2 + var3
±± subtractionsubtraction
var1 = var2var1 = var2 ±± var3var3
/ division/ division
var1 = var2 / var3var1 = var2 / var3
* multiplication* multiplication
var1 = var2 * var3var1 = var2 * var3
\\ Integer divisionInteger division
var1 = var2var1 = var2 \\ var3var3
Returns only the integer portionReturns only the integer portion
ModMod ±± modulomodulo
Var1 = var2 Mod var3Var1 = var2 Mod var3
Returns the remainder after divisionReturns the remainder after division
^^ -- ExponentiationExponentiation
VBScript Basics
VBScript Basics ±
± Logical
Logical
Operators
Operators
Concatenation
Concatenation -- &
&
³Adds´ strings together
³Adds´ strings together
Comparison
Comparison
>, <, <>, >=, <=, =
>, <, <>, >=, <=, =
Returns a ³True´ or a ³False´
Returns a ³True´ or a ³False´
E.g. var1 > 6
E.g. var1 > 6
Logical
Logical
AND, Or, Not
AND, Or, Not
VBScript Basics
VBScript Basics ±
± Contr
Contr
ol
ol
Statements
Statements ±
± If
If--Then
Then--Else
Else
Deter
Deter
mine pr
mine pr
ogram flow
ogram flow
Conditional statements
Conditional statements
If
If ±
± Then
Then
If var1 > 2 ThenIf var1 > 2 Then
Document.Write ³var1 >2´Document.Write ³var1 >2´
End If End If
If
If ±
± Then
Then ±
± Else
Else
If var1 > 2 ThenIf var1 > 2 Then
Document.Write ³var1 >2´Document.Write ³var1 >2´
ElseElse
Document.Write ³var1 <=2´Document.Write ³var1 <=2´
VBScript Basics
VBScript Basics ±
± Contr
Contr
ol
ol
Statements
Statements ±
± If
If--Then
Then--ElseIf
ElseIf
If
If ±
± Then
Then ±
± ElseIf
ElseIf
Same as nested If¶s
Same as nested If¶s
If var1 > 2 Then
If var1 > 2 Then
Document.Write ³var1 >2´Document.Write ³var1 >2´
ElseIf var1 = 2 Then
ElseIf var1 = 2 Then
Document.Write ³var1 = 2´Document.Write ³var1 = 2´
Else
Else
Document.Write ³var1 < 2´Document.Write ³var1 < 2´
End If
End If
VBScript Basics
VBScript Basics ±
± Contr
Contr
ol
ol
Statements
Statements ±
± Select
Select--Case
Case
Concise way of Concise way of writing multiple if writing multiple if--then statementsthen statements
Select Case nameSelect Case name
Case ³Bob´Case ³Bob´
Document.Write ³Bob´Document.Write ³Bob´
Case ³Mary´Case ³Mary´
Document.Write ³Mary´Document.Write ³Mary´
Case ³Bill´Case ³Bill´
Document.Write ³Bill´Document.Write ³Bill´
Case ElseCase Else
Document.Write ³Other case!´Document.Write ³Other case!´
End SelectEnd Select
VBScript Basics
VBScript Basics ±
± Looping
Looping
Repeats a command or set of commands
Repeats a command or set of commands
For
For ±
± Next
Next
For x = 1 to 20
For x = 1 to 20
Document.Write ³<br />´ & xDocument.Write ³<br />´ & x
Next
Next