VBscript Complete Reference Guide - Chapter 1

Download VBscript Complete Reference Guide - Chapter 1

Post on 21-Jul-2016

18 views

Category:

Documents

0 download

DESCRIPTION

VBscript is a very light weight and user friendly language. It is currently running in industry as one of the prominent scripting language due to its fast and easy access.www.apextgi.in

TRANSCRIPT

  • Comparing VBScript control structures to Comparing VBScript control structures to JavaScript control JavaScript control structuresstructures

    http://www.apextgi.in

  • Data Types and Control StructuresData Types and Control Structures

    JavaScript VBScript

    1 if ( s == t ) 2 u = s + t; 3 else if ( s > t ) 4 u = r; 5 else 6 u = n;

    1 If s = t Then 2 u = s + t 3 ElseIf s > t Then 4 u = r 5 Else 6 u = n 7 End If

    JavaScript VBScript

    1 switch ( x ) { 2 case 1: 3 alert("1"); 4 break; 5 case 2: 6 alert("2"); 7 break; 8 default: 9 alert("?"); 10 }

    1 Select Case x 2 Case 1 3 Call MsgBox("1") 4 Case 2 5 Call MsgBox("2") 6 Case Else 7 Call MsgBox("?") 8 End Select

    Comparing JavaScripts if structure to VBScripts If structure

    Comparing JavaScripts switch to VBScripts Select Case

  • Data Types and Control StructuresData Types and Control Structures

    JavaScript VBScript

    1 while ( !( x == 10 ) ) 2 ++x;

    1 Do Until x = 10 2 x = x + 1 3 Loop

    JavaScript VBScript 1 do { 2 ++x; 3 } while ( !( x == 10 ) );

    1 Do 2 x = x + 1 3 Loop Until x = 10

    JavaScript VBScript

    1 x = 8; 2 for ( y = 1; y < x; y++ ) 3 x /= 2;

    1 x = 8 2 For y = 1 To x 3 x = x \ 2 4 Next

    Comparing JavaScripts while to VBScripts Do Until

    Comparing JavaScripts do/while to VBScripts Do Loop/Until

    Comparing JavaScripts for to VBScripts For

  • Data Types and Control Data Types and Control StructuresStructures

    Select Case/End Select Does not require break type statement

    VBScript structures without direct JavaScript equivalents: Do Until/Loop Do/Loop Until Loop until condition becomes True

    Exit Do Immediate exit from Do While/Loop, Do/Loop While, Do

    Until/Loop or Do/Loop Until Exit For Immediate exit from For/Next

    For loop Optional Step keyword to increment or decrement

    1 VBScript2 For y = 2 To 20 Step 23 Call MsgBox( "y = " & y )4 Next

  • VBScript FunctionsVBScript Functions Predefined functions

    Variant functions IsEmpty Returns True if variant not initialized

    Math functions Cos, Sin, etc. Take arguments in radians radians = degrees /180

    InputBox Displays dialog in which user can input data

    MsgBox Displays message dialog

    VBScript functions often take optional arguments Formatting functions FormatCurrency, FormatDateTime, etc.

  • VBScript FunctionsVBScript Functions Functions for getting info about scripting engine ScriptEngine Returns Jscript, VBScript or VBA

    ScriptEngineBuildVersion Returns current build version; ID number for current release

    ScriptEngineMajorVersion Returns major version number for script engine

    ScriptEngineMinorVersion Returns minor release number

    Line continuation character Underscore character, _ Statements cannot extend beyond current line without character

  • VBScript Example ProgramsVBScript Example Programs

    Always place VBScript code inside HTML comments Prevent code from being displayed as text in browsers that do

    not understand VBScript Script variables Variables declared outside of procedures

    Const keyword Create constants

  • VBScript Example ProgramsVBScript Example Programs

    Comments Single quote () Keyword Rem (remark) Considered outdated

    Procedures: Sub keyword Procedure that does not return a value Exit Sub exits Sub procedure

    Function keyword Procedure that returns a value Exit Function exits Function procedure

  • VBScript Example ProgramsVBScript Example Programs

    Function InputBox Displays a dialog for user to input dataCall InputBox ( prompt, caption, help File,_

    x-coord, y-coord) Coordinates measured from top left (0,0). Measured in twips (1440 twips = 1 inch)

    Optional parameter help File can be left out by writing consecutive commas , ,

    _ (underscore) - line continuation character, required if statement extends beyond a line Use as many as necessary

  • VBScript Example ProgramsVBScript Example Programs Calling functions If function call has arguments in parentheses, use keyword

    Call If function assigns a variable, Call not needed

    a = Abs( z ) If parentheses not used, keyword Call not needed

    Function MsgBox Displays message dialogMsgBox "VBScript is fun!", , "Results" Displays "VBScript is fun!" with "Results" in the title

    bar Optional argument to customize buttons and icon ignored

  • 1.1SetlanguagetoVBScript

    1.2Option Explicitstatement

    1.3DefineprocedureOn ClickforthecmAddbutton

    1.4UseCInttoconvertinputvaluesfromstringsubtypetointegersubtype

    1 2356Our first VBScript7892324252627Click the button to add an integer to the total.28

    29

    30323334

  • Adding integers on a Web page using VBScriptAdding integers on a Web page using VBScript

    Input dialog

    Message dialog

  • facebook.com/apex.tgi

    twitter.com/ApextgiNoida

    pinterest.com/apextgi

    Stay Connected with us for more chapters on VB Script and JAVA Script

    http://www.apextgi.in

    Comparing VBScript control structures to JavaScript control structuresData Types and Control StructuresSlide 3Slide 4VBScript FunctionsVBScript FunctionsVBScript Example ProgramsSlide 8Slide 9Slide 10Slide 11Adding integers on a Web page using VBScriptSlide 13