VBScript ( VBS , deployed by Microsoft Visual Basic Script Edition , sometimes Visual Basic Script ) is a scripting language created by Microsoft based on the Visual Basic language, which is intended for use in applications using Active Scripting technology.
Content
- 1 Scope
- 2 Language Rules
- 3 variables
- 4 Objects, their methods and properties
- 5 Example
- 6 See also
- 7 Notes
- 8 References
Scope
VBScript scripts (scripts) are most often used in the following areas that use Microsoft products:
- in the Windows scripting server (WSH [1] ), designed to automate the administration of Windows systems ;
- server-side code in ASP web pages ;
- client scripts in Internet Explorer and other applications that use its engine , in particular HTML Application .
VBS scripts, depending on the application, can be located in separate text files (usually with the extension .vbs ) or embedded in documents in other languages (for example, HTML ).
For the scripts to work, the system must have a executing kernel (“engine” [2] ) of the language ( vbscript.dll library ).
Language Rules
The following rules work in Visual Basic:
- line length is not limited;
- case insensitive ;
- the number of spaces between parameters is not taken into account;
- the command line can be broken, and at the place of the break you need to insert the symbol "
_"; - the maximum length of a variable name is 255 characters;
- comments are indicated by the symbol “
'”. - several commands can be placed on one line, separating them with the symbol “
:”
Variables
By default, variables in scripts are automatically declared upon first use in the body of the script, unless prohibited by the Option Explicit directive. If, at the beginning of the script, declare the Option Explicit directive, then all variables must be defined in advance using the following constructions:
Dim ValueName1 'variable available to all routines;
Public ValueName2 'variable available to all routines;
Private ValueName3 'variable available only to the current program and its routines;
Constants are declared at the beginning of the script using the construct:
Const ConstName1 = Value1 'constant available to all routines;
Public Const ConstName2 = Value2 'constant available to all routines;
Private Const ConstName3 = Value3 'constant available only to the current program and its subprograms;
The type of the variable is assigned automatically after entering the first value into it. The following data types exist in Visual Basic:
- empty - uninitialized variable;
- null is an empty variable;
- boolean - boolean type, possible values: False, True or 0, 1;
- byte - 8-bit unsigned integer, possible values: 0 .. 255;
- integer - 16-bit integer, possible values: −32768 .. 32767;
- long - 32-bit integer, possible values: −2147483648 .. 2147483647;
- currency - money type, possible values: −922337203685477,5808 to 922337203685477,5807;
- single - a floating point number, possible values: −3.402823e38 .. −1.401298e-45 for negative numbers and 1.401298e-45 .. 3.402823e38 for positive numbers;
- double - a floating-point number, possible values: −1.79769313486232e308 .. −4.94065645841247e-324 for negative numbers and 4.94065645841247e-324 .. 1.79769313486232e308 for positive numbers;
- date - date, possible values: 01/01/1900 .. 01/31/9999;
- string - string variable, capacity up to 2 billion characters;
- object - a pointer to an object;
- error - error code.
In VBS scripts, it is possible to use arrays of variables that allow you to store lists, tables, and even more complex constructs. One-dimensional arrays (lists) can be dynamic, that is, they allow you to change its size during the script. All arrays are declared by the Dim command:
Dim ArrayName ( Dimension )
Objects, their methods and properties
VBScript, like its parent, the Visual Basic language, is an object-oriented programming language, that is, the basic concept is the concept of objects and classes
A class is a type that describes the structure of objects. An object implies something that has a certain behavior and presentation method, an object is an instance of a class. The class can be compared with the drawing according to which objects are created. Classes are usually designed in such a way that their objects correspond to the objects of the subject area.
All objects that VBScript works with have methods and properties. To access the method, you must specify the object, and through the point - the method with the necessary parameters.
The situation is similar with properties, but you can either assign or read properties into variables and other properties; however, you should consider the data type of variables and properties, otherwise the script will generate an incompatible data type error.
Example
Here is an example of a small program in VBScript that displays a dialog box with a message (the characters after the apostrophe are comments ):
'Variable declaration:
Dim strmessage
'Assigning a variable value:
strMessage = "Wikipedia - the free encyclopedia"
'Output window with a message:
MsgBox strMessage
By the effect of work, it is similar to direct instructions
MsgBox "Wikipedia - the free encyclopedia"
See also
- Visual basic for applications
- JScript is an alternative scripting language created by Microsoft based on ECMAScript
- KiXtart
- AutoIt
Notes
- ↑ English Windows script host
- ↑ In its essence, similar to JavaScript engines .
Links
- VBScript - The Microsoft VBScript Guide.
- The Script Center Script Repository (English) - A collection of scripts on VBScript from Microsoft.