+ All Categories
Home > Technology > VB Script

VB Script

Date post: 21-Oct-2014
Category:
View: 2,242 times
Download: 5 times
Share this document with a friend
Description:
VB Script is a subset of Visual Basic 4.0 language. It was developed by Microsoft to provide more processing power to Web pages. VB Script can be used to write both server side and client side scripting. (If you already know Visual Basic or Visual Basic for Applications (VBA), VB Script will be very familiar. Even if you do not know Visual Basic, once you learn VB Script, you are on your way to programming with the whole family of Visual Basic languages.)
Popular Tags:
26
VB Script By: Satish Sukumaran
Transcript
Page 1: VB Script

VB Script

By:

Satish Sukumaran

Page 2: VB Script

Brief about VB Script• VBScript stands for Visual Basic Scripting, is a scripting language was launched by Microsoft in1996.

VB Scripting language is a lightweight programming language.

VBScript can be used to write both client-side and server-side scripting.

Page 3: VB Script

Data Types• VBScript supports only one Data type called ‘Variant’

•A Variant is a special type of data that can contain different kinds of information, depending upon how it is used.•A variant behaves as a number when it is used in a numeric context and as a string when used in string context.

Page 4: VB Script

VBScript VariablesA variable is a "container" /Placeholder that refers to a memory

location,that stores program information that may change at run time.

Variable Declaration:

Dim :Variable declared with Dim at script level are available

To all procedures within the script.

Public: Variables are available to all procedures in all scripts.

Private: Variables are available only to the scripts in which they

are declared.

Page 5: VB Script

Naming Rules: Must begin with an alphabetic character Cannot contain an embedded period Cannot exceed 255 characters Must be unique within its scope in which it is declared.

Implicit Declaration:

You can Assign a Value to variable directly (without declaring a variable). But not a good practice, because you may misspell the variable name in one or more places, causing unexpected result when your script is run.

Option Explicit :Option Explicit to avoid incorrectly typing the name of an existing variable.

Example:Option explicitDim var_ xvar_x=1

Page 6: VB Script

ConstantsThe values that do not alter during the entire

execution of the program are called as constants.

Const keyword is used to declare constants.It is necessary to initialize the Constant

during its declaration. You cannot change the value of constants in

later script.Syntax:

const x=1 const my string=“This is my string”

Page 7: VB Script

Arrays

A Variable containing single value is called scalar variable.

Sometimes you want to assign more than one value to a single variable. Then you can create a variable that can contain a series of values. This is called an array variable.

Page 8: VB Script

Arrays (cont.)The declaration of an array variable uses

parentheses ( ) following the variable name.

Example:

dim names(2)

names(0)=“Ali“names(1)=“Imran“names(2)=“Khan"

Page 9: VB Script

Arrays (cont.)

An array can be multi dimensional.

There can be 60 (maximum) dimensions in an array.

Multiple dimensions are declared by separating the numbers in the parentheses with commas.

Page 10: VB Script

ProceduresA Sub procedure:is a series of statements, enclosed by the Sub

and End Sub statements can perform actions, but does not return a

value can take arguments that are passed to it by a

calling procedure without arguments, must include an empty

set of parentheses ()

Page 11: VB Script

Procedures (Cont)Sub Keyword is Used to declare a procedure.End Sub Keyword is Used to defining the ending

boundary of a procedure.Call Keyword is Used in order to invoke a

procedure.

Syntax:Sub mysub()

some statements End Sub

Call mysub()

Page 12: VB Script

Procedures (Cont)Procedure can take arguments that are

passed to it by calling that procedure .

Syntax:Sub procedure name(arg1,arg2)

some statements End Sub

Call mysub(value1,value2)

Page 13: VB Script

FunctionsA Function procedure:is a series of statements, enclosed by the

Function and End Function statements can perform actions and can return a value can take arguments that are passed to it by a

calling procedure without arguments, must include an empty

set of parentheses () returns a value by assigning a value to its

name

Page 14: VB Script

Functions (Cont)Function Keyword is Used to declare a Function.End Function Keyword is Used to defining the

ending boundary of a Function.<Function Name> is Used in order to invoke a

Function.

Syntax:Function myfunc()

myfunc=valuesome statements

End Function

myfunc

Page 15: VB Script

If ConditionUsing If statement we can execute a single or

block of statements when a condition     is true.

Ex:-                                  If  i=0 Then                                     msgbox "Hello"                                          i=i+1                                  End If

Page 16: VB Script

If-Else ConditionExecute a block of statement when condition is

true, otherwise execute another block of statements when condition false.

If i=2 thenmsgbox”Hello world”ElseMsgbox”Thank You”End if

Page 17: VB Script

If-Elseif Condition (cont.)Decide among several alternates.

if payment="Cash" then msgbox "You are going to pay cash!" elseif payment="Visa" then msgbox "You are going to pay with visa." elseif payment="AmEx" then msgbox "You are going to pay with American

Express." else msgbox "Unknown method of payment.“ end If

Page 18: VB Script

Select Case ConditionUsing this statement one of several groups of statements

are executed based on the expression value. Example: You can use the SELECT statement if you want to select one of many blocks of code to execute.

Select case payment    Case " Cash "    msgbox " You are going to pay cash "   Case " Visa "   msgbox " You are going to pay with Visa "   Case " AmEx"   msgbox " You are going to pay with American Express"   Case Else   msgbox " Unknown method of payment"End Select                  

Page 19: VB Script

For LoopA For loop is used for situations when you need to do something over and over again until some condition statement fails.

Ex:-

For count=0 to 3       Print (count)Next

Page 20: VB Script

For Each LoopIt is useful when you want to go through every

element in an array but you do not   know how many elements are there inside the array.

Ex:-

Dim a(2)a(0)= " Pen "a(1) =" Register" a(2)= " Copy"For Each item In a   Print(item)Next

Page 21: VB Script

Do-while loopDo-while keywords are used to execute

specified code for a set of times (until a condition remains true or a condition becomes false).

Syntax

Do While <Condition for loop>Some Statements

Loop

Page 22: VB Script

Do-while loop (cont.)

Do-While can also used in following syntax:

Do some Statements

Loop While i>10

Page 23: VB Script

Do-Until Loop Do – Until keyword is used for repeating

some set of statements until a certain condition is true.

Syntax:Do Until <Condition>

some statmemts

Loop

Page 24: VB Script

Do-Until Loop (cont.)Do-Until can also used in following syntax:

Do some statements

Loop Until <Condition>

Page 25: VB Script

Built in FunctionsVB Script provides several built in functions

that can be used just by calling them.

Few Examples:

DateTimeInt

Page 26: VB Script

Thank You !


Recommended