পৃষ্ঠাসমূহ

Search Your Article

CS

Pageviews

Showing posts with label VBScript Tutorial. Show all posts
Showing posts with label VBScript Tutorial. Show all posts

Wednesday, April 5, 2017

VBScript - Overview

VBScript stands for Visual Basic Scripting that forms a subset of Visual Basic for Applications (VBA).
VBA is a product of Microsoft which is included NOT only in other Microsoft products such as MS Project and MS Office but also in Third Party tools such as AUTO CAD.

VBScript - Syntax

Your First VBScript

Let us write a VBScript to print out "Hello World".
<html>
<body>
<script language="vbscript" type="text/vbscript">
   document.write("Hello World!")
</script>
</body>
</html>

Enabling VBScript in Browsers

NOT All the modern browsers support VBScript. VBScript is supported just by Microsoft's Internet Explorer while other browsers(Firefox and Chrome) just support JavaScript. Hence, the developers prefer JavaScript over VBScript.
Though Internet Explorer (IE) supports VBScript, many a times you may need to enable or disable this feature manually. This tutorial will make you aware of the procedure of enabling and disabling VBScript support in Internet Explorer.

VBScript - Placements

VBScript Placement in HTML File

There is a flexibility given to include VBScript code anywhere in an HTML document. But the most preferred way to include VBScript in your HTML file is as follows:
  • Script in <head>...</head> section.
  • Script in <body>...</body> section.
  • Script in <body>...</body> and <head>...</head> sections.
  • Script in an external file and then include in <head>...</head> section.

VBScript - Variables

VBScript Variables

Variable is a named memory location used to hold a value that can be changed during the script execution. VBScript has only ONE fundamental data type, Variant.
Rules for Declaring Variables:
  • Variable Name must begin with an alphabet.
  • Variable names cannot exceed 255 characters.
  • Variables Should NOT contain a period(.)
  • Variable Names should be unique in the declared context.

VBScript - Constants

Constant is a named memory location used to hold a value that CANNOT be changed during the script execution. If a user tries to change a Constant Value, the Script execution ends up with an error. Constants are declared the same way the variables are declared.

VBScript - Operators

What is an operator?

Simple answer can be given using expression 4 + 5 is equal to 9. Here, 4 and 5 are called operands and + is called operator. VBScript language supports following types of operators:
  • Arithmetic Operators
  • Comparison Operators
  • Logical (or Relational) Operators
  • Concatenation Operators

VBScript - Decision Making

Decision making allows programmers to control the execution flow of a script or one of its sections. The execution is governed by one or more conditional statements.
Following is the general form of a typical decision making structure found in most of the programming languages:

VBScript - Loops

There may be a situation when you need to execute a block of code several number of times. In general, statements are executed sequentially: The first statement in a function is executed first, followed by the second, and so on.
Programming languages provide various control structures that allow for more complicated execution paths.
A loop statement allows us to execute a statement or group of statements multiple times and following is the general from of a loop statement in VBScript.

VBScript - Events

What is an Event ?

VBScript's interaction with HTML is handled through events that occur when the user or browser manipulates a page.
When the page loads, that is an event. When the user clicks a button, that click too is an event. Another example of events are like pressing any key, closing window, resizing window, etc.

VBScript and Cookies

What are Cookies?

Web Browser and Server use HTTP protocol to communicate and HTTP is a stateless protocol. But for a commercial website, it is required to maintain session information among different pages. For example, one user registration ends after completing many pages. But how to maintain user's session information across all the web pages.

VBScript - Numbers

Description

Number functions help the developers to handle numbers in an efficient way and also helps them to convert their subtypes. It also helps them to make use of the inbuilt mathematical functions associated with VBscript.

Number Conversion Functions

Number functions help us to convert a given number from one data subtype to another data subtype.

VBScript - Strings

Strings are a sequence of characters, which can consist of alphabets or numbers or special characters or all of them. A variable is said to be a string if it is enclosed within double quotes " ".

VBScript - Arrays

What is an Array?

We know very well that a variable is a container to store a value. Sometimes, developers are in a position to hold more than one value in a single variable at a time. When a series of values are stored in a single variable, then it is known as array variable.

VBScript - Date and Time Functions

VBScript Date and Time Functions help the developers to convert date and time from one format to another or to express the date or time value in the format that suits a specific condition.

Date Functions

Function Description
Date A Function, which returns the current system date
CDate A Function, which converts a given input to Date

VBScript - Procedures

What is a Function?

A function is a group of reusable code which can be called anywhere in your program. This eliminates the need of writing same code over and over again. This will enable programmers to divide a big program into a number of small and manageable functions.
Apart from inbuilt Functions, VBScript allows us to write user-defined functions as well. This section will explain you how to write your own functions in VBScript.

VBScript - Dialog Boxes

What is a Dialog Box ?

VBScript allows the developers to interact with the user effectively. It can be a message box to display a message to a user or an input box with which user can enter the values.

Object Oriented VBScript

What is an Object

VBScript runtime objects help us to accomplish various tasks. This section will help you understand how to instantiate an object and work with it.

Syntax

In order to work with objects seamlessly, we need to declare the object and instantiate it using Set Keyword.
Dim objectname    'Declare the object name
Set objectname = CreateObject(object_type)

VBScript - Regular Expressions

What are Regular Expressions?

Regular Expressions is a sequence of characters that forms a pattern, which is mainly used for search and replace. The purpose of creating a pattern is to match specific strings, so that the developer can extract characters based on conditions and replace certain characters.

VBScript - Error Handling

There are three types of errors in programming: (a) Syntax Errors and (b) Runtime Errors (c) Logical Errors.

Syntax errors

Syntax errors, also called parsing errors, occur at interpretation time for VBScript. For example, the following line causes a syntax error because it is missing a closing parenthesis:
<script type="text/vbscript">

dim x,y
x = "Tutorialspoint"
y = Ucase(x

</script>

Runtime errors

Runtime errors, also called exceptions, occur during execution, after interpretation.
For example, the following line causes a runtime error because here syntax is correct but at runtime it is trying to call fnmultiply, which is a non-existing function:
<script type="text/vbscript">
  
  Dim x,y
  x = 10
  y = 20
  z = fnadd(x,y)
  a = fnmultiply(x,y)
  Function fnadd(x,y)
      fnadd = x+y
  End Function

</script>

Logical errors

Logic errors can be the most difficult type of errors to track down. These errors are not the result of a syntax or runtime error. Instead, they occur when you make a mistake in the logic that drives your script and you do not get the result you expected.