• No results found

VBScript

N/A
N/A
Protected

Academic year: 2021

Share "VBScript"

Copied!
19
0
0

Loading.... (view fulltext now)

Full text

(1)

Scripting Languages

Scripting Languages

Scripting Languages

-Scripting Languages -

-

-VBScript

VBScript

VBScript

VBScript

(2)

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 

(3)

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 

(4)

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)

(5)

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 

(6)

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 

(7)

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)

(8)

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

(9)

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

obust as VB

(10)

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

(11)

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 

(12)

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 

(13)

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

(14)

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

(15)

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

(16)

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´

(17)

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 

(18)

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 

(19)

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

References

Related documents

quantifying changes in land use and land cover at multiple scales, then evaluating the impacts of such changes on forest birds. The primary goal of this study was to examine changes

The positive and significant relationship between farm size, seed, fertilizer and family labour indicate that if more of these variables are used in groundnut farming, there will

Persons charged with further claims that the Knights Templar of Europe has given him permission to... Persons charged with first say that I mean, but dishes it up until we

Through ResearchOne the integrated care records of more than 25 million patients have the capacity to support research, with information from over 4500 health units in primary,

The relational contracting model highlighted the importance of a need to develop a vision for partnering, stakeholder analysis and consensus building among them, empowerment

We demonstrated that nuclear DNMT1 like E2F1 increases during the metastatic progression of human prostate cancer and these changes coupled with decreases in AR expression

This paper presents a new approach com- bining Branch and Price (B&amp;P) with metaheuristics to derive various high-quality schedules as solutions to a nurse scheduling problem

The Red Box recorder not only offers a single software solution that records, stores, archives and delivers replay for 4 to 500 concurrent recordings (from mixed devices), it