Monday, November 3, 2014

VBScript Declaration and Initialisation

' Basic program to understand declaration and initialization
' Save the File with .vbs extension


Dim a 'Declaration

a=10 'Initialisation

Dim b: b=" Testing"    ' Declaration and Initialisation

MsgBox (a)

a=20

MsgBox (a)

MsgBox (b)


--------------------------------------------------------------------------

Dim Name         'Single Declaration
Dim EmpID,Age 'Multiple Declaration

Name= " Sunil " 'Initialisation
EmpID=101
Age =32

MsgBox (Name)
MsgBox (EmpID)
MsgBox (Age)



--------------------------------------------------------------------------

'Basic program to understand declaration and initialisation.


'Dim Name ="Raj"  'This statement will fail because declaration and intialisation can not be

done in same statment.

Dim EmpID1,EmpID2,EmpID3

EmpID1=007
MsgBox "EmpID1 = " & EmpID1                   ' Outout ---> EmpID1=7

EmpID2="007"
MsgBox "EmpID2 = " & EmpID2                    ' Outout ---> EmpID2=007

EmpID3=007.235
MsgBox "EmpID3 = " & EmpID3                    ' Outout ---> EmpID3=7.235



--------------------------------------------------------------------------

Dim fName ''Declaration

fName="Dinesh " ''Initialisation

lName= "Jangra" ''Declaration and Initialisation

MsgBox fName+LName '' Here lName and LName both reffer to same variable because VB is case insenstive scripting language.