VBScript Procedures

VBScript Procedures :

VBScript has two kinds procedures:
  1. Sub procedure.
  2. Function procedure.

Sub Procedures :

A Sub procedure:
  1. it is some claims, surrounded by the Sub and End Sub statements.
  2. may do measures, but does not return a benefit.
  3. will take arguments.
Sub mysub(argument1,argument2)
  some statements
End Sub

Function Procedures :

A Purpose technique:
  1. it is a series of claims, closed by the Purpose and End Purpose claims.
  2. can do activities and can return a value.
  3. may take fights which are transferred to it by way of a contacting technique.
  4. without fights, should contain an empty pair of parentheses ().
  5. results a value by assigning a value to its title.
Function myfunction(argument1,argument2)
  some statements
  myfunction=some value
End Function

Calling a Procedure :

This simple function procedures is called to calculate the sum of two arguments:

Function myfunction(a,b)
myfunction=a+b
End Function 

document.write(myfunction(5,4))

The function “myfunction” will return the sum of argument “a” and argument “b”. In this case 9.

VBScript Conditional Statements

Conditional Statements :

Conditional statements are accustomed to perform different activities for different decisions.
In VBScript we have four conditional statements:
  • If statement – executes a set of signal whenever a situation is true.
  • If…Then…Else statement – pick one of two units of lines to implement.
  • If…Then…ElseIf statement – pick one of numerous units of lines to implement.
  • Pick Case statement – pick one of numerous units of lines to implement.

If…Then…Else :

Use the If…Then…Else record if you intend to

  • perform some signal if a condition holds true
  • pick one of two blocks of signal to perform

If you intend to perform only one record each time a condition holds true, you can write the signal using one line:

If i=10 Then alert(“Hello”)

There’s number ..Else.. in that syntax. You just inform the rule to perform one activity if your problem is true (in that situation If i=10).
If you intend to execute several record whenever a problem is true, you have to put each record on split lines, and conclusion the record with the keyword “Conclusion If”:

If i=10 Then
alert(“Hello”)
i = i+1
End If


There is no ..Else.. in the example above either. You just tell the code to perform multiple actions if the condition is true.

VBScript Variables

VBScript Variables :

As with algebra, VBScript variables are accustomed to maintain values or expressions.
A variable can have a quick title, like x, or perhaps a more detailed title, like carname.
Principles for VBScript variable names:

  • Should start out with a letter 
  • Can not include a time (.)
  • Can not surpass 255 characters

In VBScript, all variables are of type plan, that can store several types of data.

Declaring VBScript Variables :

Creating parameters in VBScript is most often called “announcing” variables.
You can declare VBScript parameters with the Poor, Public or the Personal statement. Similar to this:

Dim x
Dim carname


Now you have made two variables. The name of the variables are “x” and “carname “.
You can also declare variables by which consists of name in a script. Such as this:

carname=”Volvo”

So you have made a variable. The name of the variable is “carname “.But, this process is not just a good practice, since you can misspell the variable name later in your software, and that may trigger odd results whenever your software is running.
If you misspell for example the “carname” variable to “carnime”, the software will instantly develop a new variable named “carnime”.  To avoid your software from carrying this out, you can use the Choice Specific statement. This statement makes one to declare your entire parameters with the poor, public or individual statement.
Put the Choice Specific statement on the top of one’s script. Similar to this:

Option Explicit
Dim carname
carname=some value


Assigning Values to Variables :

You assign a value to a variable like this:

carname=”Volvo”
x=10

The variable title is on the remaining part of the appearance and the worthiness you intend to allocate to the variable is on the right. Today the variable “carname” has the worthiness of “Volvo”, and the variable “x” has the worthiness of “10 “.

Lifetime of Variables :

How long a variable exists is their lifetime.
When you declare a variable inside a procedure, the variable can only just be accessed within that procedure. When the process exits, the variable is destroyed. These variables are called regional variables. You can have regional variables with exactly the same title in various procedures, since each is acknowledged just by the process in which it’s declared.
If you declare a variable outside a procedure, most of the procedures in your page may entry it. The duration of these variables begins when they’re declared, and stops once the page is closed.

Array Variables :

An variety variable is used to keep numerous prices within a variable.
In the next example, an variety containing 3 components is reported:

Dim names(2)

The amount shown in the parentheses is 2. We start at zero which means this range includes 3 elements. This is a fixed-size array. You assign knowledge to each of the aspects of the range such as this:

names(0)=”Tove”
names(1)=”Jani”
names(2)=”Stale”


Likewise, the info could be recovered from any factor using the list of this variety factor you want. Similar to this:

mother=names(0)

You can have around 60 dimensions within an array. Multiple dimensions are reported by splitting up the numbers in the parentheses with commas. Here we’ve a two-dimensional variety consisting of 5 lines and 7 articles:

Dim table(4,6)

Introduction To VBScript

What is VBScript?

  • VBScript is really a scripting language
  • A scripting language is really a light coding language
  • VBScript is really a light edition of Microsoft’s coding language Visible Basic.
  • VBScript is a Microsoft scripting language.
  • VBScript could be the standard scripting language in ASP (Active Server Pages).
  • You can test out VBScript in Internet Explorer.

VBScript Editor :


VBScript is really a scripting language. Nevertheless, it should not be used for scripting in the browser.
Web Explorer helps VBScript. This allows us to experiment with VBScript in the browser, without the necessity for a website server. With this on the web manager, you can revise the VBScript rule, and select a switch to see the result: