VBScript Introduction

May 16, 2018 | Author: muralidharpalda | Category: Subroutine, Parameter (Computer Programming), Html, Letter Case, Scripting Language
Share Embed Donate


Short Description

Download VBScript Introduction...

Description

VBScript Introduction: Before you continue you should have a basic understanding of the following: 

HTML / XHTML

.

What is VBScript? • •

VBScript is a scripting language A scripting language is a lightweight programming language.

A lightweight programming language is one that is designed to have very small memory footprint, footprint, is easy to implement (important when porting when porting a language), and/or  has minimalist syntax and features. C may be said to be lightweight, as its hardware assumptions are minimal (it is used to program micro controllers, controllers, for example) •

VBScript is a light version of Microsoft's programming language Visual Basic

How does it Work? When a VBScript is inserted into an HTML document, the Internet browser will read the HTML and interpret the VBScript. The VBScript can be executed immediately, or at a later event. We have to write VB Script in notepad or Word Pad and save with .vbs extension. We can write an independent vb script file or we can embedded in to an HTML file. VBScript Variable:

A variable which holds a particular pa rticular value or expression at an instance of time. Rules for VBScript variable names: • • •

Must begin with a letter. Cannot contain a period (.) Cannot exceed 255 characters.

 Note: data.

In VBScript, all variables are of type variant , that can store store different types of 

Declaring VBScript Variables: Declaring is in the sense creating a variable. We can do this by declaring the variable as dim (Dimension), public and as private also. For Ex: Dim x Dim myname We can also create and assign a value to particular variable at a time. For Ex: myname=”Sachin”

OPTION EXPLICIT: If we specify option explicit, we can’t assign a value to variable. I.e. we have to declare the variable first before assigning a value to it. By default VBScript allows us to create a variable and assign a value without declaring it. For Ex: Dim a a=10 msgbox a

Will display output 10 by showing a pop-up small window. Option explicit a=10 msgbox a

The MsgBox(VBScript is not CASE SENSITIVE) function displays a message box, waits for the user to click a button, and returns a value that indicates which button the user clicked. Displays an error dialog box showing that variable an undefined.

Sample Examples: 1. Dim a, b, c a = 10 b = “20” c=a+b msgbox c output: 30 Because it internally converts string into integer, depending on the operation it perform operation.

-----------------------------------------------------2. dim a,b,c a = "10"  b = "20" c=a+b msgbox c 0utput: 1020 Here both variables values given as strings, hence it will append simply.

---------------------------------------------------------------------Note: No need to place semicolon (;) at the end of each line in VBScript.

3.

dim a,b,c a=int(inputbox("Enter a value"))  b=int(inputbox("Enter b value")) c=a+b msgbox c

The InputBox function displays a dialog box, where the user can write some input and/or  click on a button. If the user clicks the OK button or presses ENTER on the keyboard, the InputBox function will return the text in the text box. If the user clicks on the Cancel  button, the function will return an empty string ("").

We can give comments in VBScript as follows ‘ourcomment

Conditional statements in VBScript: There are two Conditional Structures in VBScript.

Conditional statements are used to perform different actions for different decisions. In VBScript we have four conditional statements: • • • •

If statement - executes a set of code when a condition is true. If...Then...Else statement - select one of two sets of lines to execute. If...Then...Else If statement - select one of many sets of lines to execute. Select Case statement - select one of many sets of lines to execute. (Like Switch case in C, C++ and Java languages).

Examples:

4.

dim a,b,c a = 10 b = 20 if a < b then msgbox a else msgbox b end if 

Select Case You can also use the "Select Case" statement if you want to select on e of many blocks of  code to execute. Syntax: Operation “Add” (Here we are giving Combination of Upper and lower case). Select Ucase Case Case “ADD” Case “SUB” Case “DIV” Case “MUL” End select Note: The UCase function converts a specified string to uppercase. (To overcome the mismatch we are writing as Ucase, which converts lowercase letter into uppercase ones).

For Ex:

5.

dim a,b,c a=int(inputbox("enter the value of a")) b=int(inputbox("enter the value of b")) c=int(inputbox("enter the value for 1.add,2.sub,3.div"))

select case c case 1 msgbox (a+b) case 2 msgbox (a-b) case 3 msgbox (a/b) case 4 msgbox(“Invalid operation’)

end select

6.

Mid function Functionality str="Welcome to VBScript" l=len(Str) msgbox " The length of the String " &l for i=1 to l c = mid(Str,i,1) msgbox " "& i &" Character is " &c next

7.

Fibonacci Series

option explicit Dim n,f1,f2,f3 n = int(inputbox("Enter n value")) f1 = 0 f2 = 1 msgbox f1 msgbox f2 do until n
View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF