+ All Categories
Home > Documents > VBScript - Most Popular Scripting Language

VBScript - Most Popular Scripting Language

Date post: 02-Jun-2018
Category:
Upload: apextgi
View: 233 times
Download: 0 times
Share this document with a friend

of 19

Transcript
  • 8/11/2019 VBScript - Most Popular Scripting Language

    1/19

    VB Script

    1

  • 8/11/2019 VBScript - Most Popular Scripting Language

    2/19

    Subjects forSession

    Vbscript fundamentals.

    Variant subtypes.

    Variables.

    Option Explicitstatement.

    Keywords.

    Scope and liftime of variables.

    Dim, Privateand Publicstatements.

    Remstatement.

    2

  • 8/11/2019 VBScript - Most Popular Scripting Language

    3/19

    What is VBScript?

    A Safe subset of visual basic

    The VBScript ode is case !nsensitive.

    "icrosoft Visual Basic Scriptin# $dition brin#sactive scriptin# to a wide variety of environments,includin# Web client scriptin# in "icrosoft !nternet$%plorer and Web server scriptin# in "icrosoft!nternet !nformation Service &!!S'.

    3

  • 8/11/2019 VBScript - Most Popular Scripting Language

    4/19

    "icrosoft( Script Timeline

    4

    !nternet

    $%plorer ).*+-

    Version/.* Version0.*

    !!S 0/0-

    !nternet$%plorer 1.*

    +-2

    Version).*

    Windows-+

    Version)./ Version1.*Version3.*

    VisualStudio !nternet$%plorer 3.*

    Win 4T 3.*

    4ote5 6uic7Test uses VBScript 3.

  • 8/11/2019 VBScript - Most Popular Scripting Language

    5/19

    Scriptin# for Speci8c 9latforms

    VBScript

    : desi#ned to run on multiple platforms that use theActive; Scriptin# !nterface.

    VBA &VB for Applications': "ore sophisticated customi

  • 8/11/2019 VBScript - Most Popular Scripting Language

    6/19

    VBScript has only one data type called a Variant.

    A Variantis a special 7ind of data type that cancontain di=erent 7inds of information, dependin# onhow it is used.

    Because Variantis the only data type in VBScript, itis also the data type returned by all functions inVBScript.

    At its simplest, a Variantcan contain either numericor strin# information.

    A Variantbehaves as a number when you use it in anumeric conte%t and as a strin# when you use it in astrin# conte%t.

    6

  • 8/11/2019 VBScript - Most Popular Scripting Language

    7/19

    VBScript >ata TypesVariant Subtypes

    Beyond the simple numeric or strin# classi8cations, aVariantcan ma7e further distinctions about thespeci8c nature of numeric information.

    or e%ample, you can have numeric information thatrepresents a date or a time.

    When used with other date or time data, the result isalways e%pressed as a date or a time.

    @ou can also have a rich variety of numeric informationran#in# in si

  • 8/11/2019 VBScript - Most Popular Scripting Language

    8/19

    VBScript >ata TypesVariant Subtypes

    8

    Subtype Description

    $mpty Variantis uninitiali

  • 8/11/2019 VBScript - Most Popular Scripting Language

    9/19

    Variables

    A variable is a convenient placeholder that refers to acomputer memory location where you can storepro#ram information that may chan#e durin# thetime your script is runnin#.

    or e%ample, you mi#ht create a variable calledlic7ount to store the number of times a user clic7san obHect on a particular Web pa#e.

    you only have to refer to a variable by his name to

    see or chan#e its value.

    9

  • 8/11/2019 VBScript - Most Popular Scripting Language

    10/19

    >eclarin# Variables

    @ou declare variables e%plicitly in your script usin# theDimstatement, the Publicstatement, and the Privatestatement. or e%ample5

    Dim>e#reesahrenheit

    @ou declare multiple variables by separatin# eachvariable name with a comma. or e%ample5

    DimTop, Bottom, Deft, Ii#ht

    10

  • 8/11/2019 VBScript - Most Popular Scripting Language

    11/19

    >eclarin# Variables

    @ou can also declare a variable implicitly bysimply usin# its name in your script.

    That is not #enerally a #ood practice because

    you could misspell the variable name in one ormore places, causin# une%pected results whenyour script is run.

    or that reason, the Option Explicitstatement is available to reJuire e%plicit

    declaration of all variables.

    11

  • 8/11/2019 VBScript - Most Popular Scripting Language

    12/19

    Gption $%plicit Statement

    orces e%plicit declaration of all variables in a script.

    !f used, the OptionExplicitstatement must appearin a script before any other statements.

    When you use the OptionExplicitstatement, youmust e%plicitly declare all variables usin# the Dim,Private, Public, or ReDimstatements. !f youattempt to use an undeclared variable name, an erroroccurs.

    Tip se OptionExplicitto avoid incorrectly typin#the name of an e%istin# variable or to avoid confusionin code where the scope of the variable is not clear.

    12

  • 8/11/2019 VBScript - Most Popular Scripting Language

    13/19

    "ust be#in with an alphabetic character.

    annot contain an embedded period.

    "ust not e%ceed 033 characters.

    "ust be uniJue in the scope in which it is

    declared.

    13

    Tip meanin#full pre8% to variables to indicate thesubtypes i.eiounter &inte#er', str4ame &Strin#', bla# &Boolean',dteToday &>ate'

  • 8/11/2019 VBScript - Most Popular Scripting Language

    14/19

    $mpty: The Empty7eyword is used to indicate an uninitiali

  • 8/11/2019 VBScript - Most Popular Scripting Language

    15/19

    A variableLs scope is determined by where you declare it.

    When you declare a variable within a procedure, only code within thatprocedure can access or chan#e the value of that variable.

    !f you declare a variable outside a procedure, you ma7e it reco#ni

  • 8/11/2019 VBScript - Most Popular Scripting Language

    16/19

    DimvarnameM!MsubscriptsN"NM# varnameM!MsubscriptsN"NN $ $ $

    >eclares variables and allocates stora#e space.

    Variables declared with Dimat the script level are available to allprocedures within the script.

    At the procedure level, variables are available only within the

    procedure.

    @ou can also use the Dimstatement with empty parentheses todeclare a dynamic array.

    Note When you use the Dimstatement in a procedure, you

    #enerally put the Dimstatement at the be#innin# of the

    procedure.

    16

  • 8/11/2019 VBScript - Most Popular Scripting Language

    17/19

    PrivatevarnameM!MsubscriptsN"NM# varnameM!MsubscriptsN"NN $ $ $

    >eclares private variables and allocates stora#e space.

    9rivate statement variables are available only to the script in whichthey are declared.

    The followin# e%ample illustrates use of the Privatestatement5

    17

    Private"y4umber 9rivate Variant variable.Private"yArray&-' 9rivate array variable. "ultiple 9rivate declarations of Variant variables.Private"y4umber, "yVar, @our4umber

  • 8/11/2019 VBScript - Most Popular Scripting Language

    18/19

    PublicvarnameM!MsubscriptsN"NM# varnameM!MsubscriptsN"NN $ $ $

    >eclares public variables and allocates stora#e space.

    Publicstatement variables are available to all procedures inall scripts.

    @ou can also use the Publicstatement with emptyparentheses to declare a dynamic array.

    18

    Public"y4umber 9ublic Variant variable.Public"yArray&-' 9ublic array variable.

    "ultiple 9ublic declarations of Variant variables.

    Public"y4umber, "yVar, @our4umber

  • 8/11/2019 VBScript - Most Popular Scripting Language

    19/19

    19


Recommended