VBScript

May 15, 2018 | Author: Vinod Mishra | Category: Scripting Language, Data Type, Java Script, Visual Basic For Applications, Basic
Share Embed Donate


Short Description

Download VBScript...

Description

Scripting Languages VBScript

Compiled Languages   

Source File (Text) Pre--pr  Pre ocess ± Replace/update directives Compile ± Create assembly language file  

 

Assemble ± Create binary executable Advantages   



Compilers and machine specific Once compiled, cannot be decompiled (easily) ± Not 11-to to--1

Fast! (Relatively) Safe fr  om alteration/theft Use traditional languages (smaller learning curve, lots of  talent available)

Disadvantages   

Not portable Need to rere-compile to change Not efficient f  or simple tasks

Scripting Languages Backgr  ound 



Unix Shell scripts ± sh, csh, bash, tcsh, zsh, ksh 

Allowed easier perf  or  mance of  basic system tasks



Text commands could be ³pr  ocessed´



Same concept as batch files

Standalone scripting languages 

Awk, sed, grep, etc«



Allowed limited power to do repetitive tasks easy



Made f  or specificspecific-purpose

Scripting Languages - General      

TCL/TK Python PERL Used f  or  more advanced pr  ogramming 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. f  or addressing of  hardware)

Scripting Languages ± Web Based  

Originally PERL was most popular thr  ough 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 f  or the web Only Server Side PERLEXAMPLE1

Web Scripting ± JavaScript History  



   

  

~1994 Netscape begins building LiveScript! Netscape f  or  ms alliance with Sun, gains naming rights to Java name Renames LiveScript Javascript, and releases with br  owser 2.0 Micr  osoft responds with VBScript Micr  osoft response with Jscript Netscape fires back with 1.1, 1.2 versions ECMA ± Eur  opean Computer Manufacturers Association ± creates non non--partisan standard Javascript designed f  or clientclient-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 pr  ogramming language Contained and IDE, support f  or GUI tools f  or display Became overnight success

Visual Basic f  or Applications    

Subset of Visual Basic Created to extend other pr  ograms (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 

Pr  oblem .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 realreal-time calculations



Removed the limitations of PERL



Still a bit slow, interpreted, and not quite as r  obust as VB

VBScript Basics 

tag  

delineates scripting language code will f  ollow Attributes   

    



type=³text/vbscript´ language=´vbscript´ or ³vbs´ runat = ³server´ (default is br  owser)

VBScript is Case insensitive Whitespace is ignored Comments should use µ or Rem Code is denoted by lines.  T o span multiple lines, use _  Code outside of a subr  outine 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   

Contr  olled by VBScript engine 0 -Empty ± Declared, but no value is assigned 1 -Null ± Contains no valid data 



11 - Boolean 

        

Var = NULL Var1 = True

17 - Byte ± 0 ± 255 2 - Integer 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 - Err  or 

VBScript Basics ± Variable Operations 

Deter  mining the variable subtype    



VBScript can perf  or  m operations on two variants without needing you to make the types agree   



Var1 = 7 Var2 = 123.23 Var3 = Var1 + Var2

Constants   



VarType (var1) Returns numeric representation of the datatype TypeName (var1) Returns actual name of type!

Const PI 3.14 Usually capitalized Cannot be changed

VBEXAMPLE2

VBScript Basics ± Math Operators 

+ addition 



± subtraction 





var1 = var2 \ var3 Returns only the integer portion

Mod ± modulo  



var1 = var2 * var3

\ Integer division 



var1 = var2 / var3

* multiplication 



var1 = var2 ± var3

/ division 



var1 = var2 + var3

Var1 = var2 Mod var3 Returns the remainder after division

^ - Exponentiation 

var1 = var2 ^ var3

VBScript Basics ± Logical Operators 

Concatenation - & 





Comparison 

>, =, 6

Logical 



³Adds´ strings together 

AND, Or, Not

VBEXAMPLE3

VBScript Basics ± Contr  ol Statements ± IfIf  -ThenThen-Else  

Deter  mine pr  ogram flow Conditional statements 

If ± Then If  

If var1 > 2 Then 

 

Document.Write ³var1 >2´

End If 

If ± Then ± Else If  

If var1 > 2 Then 



Else 



Document.Write ³var1 >2´ Document.Write ³var1 2 Then 



ElseIf var1 = 2 Then 





Document.Write ³var1 = 2´

Else 



Document.Write ³var1 >2´

Document.Write ³var1 < 2´

End If 

VBEXAMPLE4

VBScript Basics ± Contr  ol Statements ± Select Select--Case 

Concise way of  writing multiple if  if--then statements



Select Case name 

Case ³Bob´ 



Case ³Mary´ 



Document.Write ³Mary´

Case ³Bill´ 



Document.Write ³Bob´

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  

For x = 1 to 20 





Document.Write ³´ & x

Next

VBEXAMPLE6

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF