Updated March 8, 2023
Introduction to VBScript Commands
VBScript is Visual Basic Scripting Edition. It is a scripting language that is distributed by Microsoft and is similar to Visual Basic and its applications. Usually, VBScript is primarily used in QTP (Quick Test Professional). It is considered to be a lightweight scripting language that has a fast interpreter. It needs Active Server Pages on the server-side for creating dynamic web pages, and on the client-side, Microsoft Internet Explorer is used. Let us have a look at all the different commands that can be used in VBScript.
Basic VBScript Commands
Let us discuss some basic commands:
- Formatting in VBScript:
The code in VBScript can be written in a single line or multiple lines. When using a single line, colons can be used when two or more lines of VBScript is to be written on a single line. Colons are like line separators.
For multiple lines, and the line being lengthy, underscore can be used to break them.
- Empty: This keyword helps to indicate an uninitialized variable value. This type of variable is first created and if no values are assigned or if the variable value is explicitly set to empty.
- Declaring and assigning values to variables: Variables in VBScript are declared using the ‘dim’ keyword. All declared variables are variant by default. There is no need of mentioning the data type in VBScript. To assign values, it is similar to algebraic expressions. The variable name on the left-hand side is assigned with a value on the right-hand side with the help of ‘=’.
- Declaring Constants: Constant is a memory location that has a value stored which cannot be changed. If a user tries changing any constant value, then an error would occur. The constant can be defined as private or public. Public constants are accessible by everyone, and private constants can be accessed only by users who created them.
- Decision making in VBScript: In order to apply conditions and allow programmers to control the execution of the script, conditional statements must be defined. These are if, if…Else, if..elseif..elsestatements. In addition to this switch, statements can also be used. These help in considering all conditional statements and help in assessing all necessary conditions.
- VBScript Placement in HTML file: A VBScript command code is very similar to HTML code. As a result, it can be placed in an HTML document. The preferred way for the script is placing the <head> in <head> section and <body> in <body> section. If a user wants to run the script when a particular event happens then, the user can place the script in the body.
- Operators in VBScript: VBScript supports all operators. To begin with, it can operate using Arithmetic operators, comparison operators, logical operators, and concatenation operators. The arithmetic operators help in arithmetic operations like addition, subtraction, multiplication, etc. All comparisons can also be done by making use of <,> or =.
- Loops in VBScript: Like all other languages requires that some task needs to be performed in iteration VB, which also has the facility to run iterations. This can be done by making use of loop, do..while loop, do..until loops, etc. All these help in executing some statements until the required condition is not satisfied. All these looping structures do need that a condition is specified to terminate the iterations.
- Date functions: VBScript command provides different date and time functions. In addition, to just give the date, it also provides dateAdd, dateDiff, datePart functions, which add, give difference and give a part of the date, respectively.
- Cdbl: This is a function that converts a given number of any variant to a double.
Intermediate VBScript Commands
Given below are some intermediate commands:
- Abs: This VBScript command gives the absolute value of any number which is provided.
- ChrB: This command helps to return the string character which is present to CHrCode.
- FIleSystemObject: This VBScript command helps in working with different drives, folders, and files.
- InStrRev: VBScript command also has string functions. This function helps in finding one string within another string in reverse format. It starts traversing from the end and finds the string.
- RTrim: If a user wants to remove unwanted spaces from any string expression, then this function is useful.
- Split: This function enables the user to parse the string of delimited values into an array.
- CreateObject: This command is used when a user wants to create an automation objector wants to run an external command to automate.
- Troubleshooting: When a user wishes to troubleshoot data, then F12 can be pressed to open developer tools. Then in the left toolbar, Emulation settings can be chosen, and the change document model can be changed from default to 10.
- Arrays: Arrays can be declared in a similar way to any variable. The difference is that this uses parenthesis. The values can further be assigned by specifying the array index value against each value that is being assigned.
- TimeSerial: This function gets the time in the format of specific hours, minutes and seconds.
Advanced VBScript Commands
The advanced commands are as explained below:
- VBScript Procedures: A function is a reusable code that can be used anywhere in the code. The functions require a definition. It defines the structure of the function. Once this function is defined, then it can be called from anywhere in the code where required. Parameters can also be passed while calling these functions. Once this is done, functions can return values that will be used in the code.
- RegExp Object: In order to work with different patterns of strings, different regular expressions can be used. They can be used when a pattern needs to be defined or an IgnoreCase where all possible matches are set to true or false. It can also be used to declare global matches in the entire code.
Tips and Tricks to use VBScript commands
- Make use of Global Variables for key values
- Make use of the Ping command to check if a computer is present.
- Perform ‘runAs’ without specifying any specific credentials.
- The default script on your host machine should be Cscript.exe
VBScript is a lightweight and active scripting language and is mostly used for Quick Test Professional. It provides different functions, constants, regular expressions, etc., which make it easy and efficient to work and automate processes.
This has been a guide to VBScript Commands. Guide to Sqoop Commands. Here we have discussed basic, intermediate, and advanced VBScript Commands and tips and tricks to use effectively. You may also look at the following article to learn more –