Beruflich Dokumente
Kultur Dokumente
1.Start Notepad.
2.Write your script. For example purposes, type Msgbox "Hello VB Script"
3.Save this text file with a .vbs extension (instead of the default .txt extension). For
example, Hello.vbs
5.Windows Script Host invokes the VB Script engine and runs your script. In the example, a
message box is displayed with the message "Hello VB Script"
Comments
Rem comment (After the Rem keyword, a space is required before comment.)
Or
Select block of statement and use short cut key Ctrl + M (for comment)
Select comment block and use short cut key Ctrl + Shift + M (for uncomment)
//////////////////////////////////////////////////
The scope of a variable defines whether a variable will be accessible in the whole
function or will be accessed only to its local instance.I have defined earlier in the
tutorials that they can also be deemed as a local variables or can be deemed as a
global variables.
For ex.
It is clear from the above example about the scope of the variable that the variable
name will be available to the whole script as it is declared outside sub procedure so
enhance his behaviour to the global as compared to the variable name age which is
defined inside the sub procedure hence making his behaviour local and will be only
accessed in this sub procedure only.
VbScript deals with a single datatype called variant. Datatype means the kind of the
data a variable will store.It can be a character data,string data,number data , byte
data and a Boolean data. But you don?t have to worry in Vb Script as it only has a
datatype of variant to store any type of data.
Arrays may either be static or dynamic. A static array has its dimensions pre-
defined and may not be re-sized, whereas a dynamic array does not have a pre-
defined number of dimensions and must be resized to store any data. To define any
of the two arrays first use either the Dim, Public, or Private statments as you would
with a normal variable. Then, to define a one-dimensional static array with three
elements, you could go:
Dim myArray(2)
To assign values to each element go:
myArray(0) = 34
myArray(1) = 45
myArray(2) = 12
You may have also defined the above array by using the Array( ) function like so:
Dim A
A = Array(34,45,12)
Arrays may be defined with as many as 60 dimensions. Array dimensions are
separated by commas. For example to define a three-dimensional array you could
go:
Public myArray(4, 7, 9)
Where the first dimension has 5 elements, the second has 8 elements, and the last
has 10 elements.
Dynamic arrays have no dimensions when they are defined and cannot contain data
until they are re-dimensioned. To define a dynamic array simply go: Dim myArray( )
How Do I Re-Dimension Arrays?
You may only re-dimension dynamic arrays. To do so, use the ReDim statement in the same
manner as either the Dim, Public, or Private statments. For example to re-dimension an existing
dynamic array you could go:
ReDim myArray(5, 5)
Note that using the ReDim statement will reset all data within the array. To keep the data from
being erased use the Preserve statement in conjuction with the ReDim statement like so:
ReDim Preserve myArray(5, 5)
There is no limit to the number of times you can resize a dynamic array, but if you make an array
smaller than it was, the data in the eliminated elements will be lost.
There are many useful constants present in Visual basic script which you can use in
your code. They ease your work load by remembering value and implementing in
the code. Maintenance is easy with VB Script because it can easily change the
feature of constants.
What is VBScript?
Give examples where VB script can directly run on users system with
Windows as OS?
What Is The Difference Between the Dim, Public, and Private Statements?
Private statement variables are available only to the script in which they are
declared.
Public statement variables are available to all procedures in all scripts.
Variables declared with Dim at the script level are available to all procedures within
the script. At the procedure level, variables are available only within the procedure.
The Variant datatype can contain a wide array of subtypes, thus, the programmer
need not worry about making sure that certain variables are capable of supporting a
specific type of data. The following table shows the subtypes of data that a Variant
can contain.
When you use the Option Explicit statement, you must explicitly declare all variables using the
Dim, Private, Public, or ReDim statements. If you attempt to use an undeclared variable name,
an error occurs.
Use Option Explicit to avoid incorrectly typing the name of an existing variable or to avoid
confusion in code where the scope of the variable is not clear.
How does VBScript differ from JavaScript and which proves better? State
the reason for the same