+ All Categories
Home > Documents > Vbscript Introduction

Vbscript Introduction

Date post: 22-Nov-2014
Category:
Upload: abdul-rehman
View: 154 times
Download: 5 times
Share this document with a friend
Popular Tags:
50
VBSCRIPT INTRODUCTION.
Transcript
Page 1: Vbscript Introduction

VBSCRIPT INTRODUCTION.

Page 2: Vbscript Introduction

What is VBScript?• Visual Basic Script Language (VBScript) is

one of Microsoft’s scripting languages that is commonly associated with Server-side and Client-side web applications. However, Microsoft has opened up VBScript to developers and now VBScript can be found in a variety of applications.

Page 3: Vbscript Introduction
Page 4: Vbscript Introduction
Page 5: Vbscript Introduction
Page 6: Vbscript Introduction
Page 7: Vbscript Introduction
Page 8: Vbscript Introduction
Page 9: Vbscript Introduction
Page 10: Vbscript Introduction
Page 11: Vbscript Introduction

The Message Box.

Syntax:MsgBox prompt, buttons, title

Examples:MsgBox “Hello”MsgBox “Hello”,vbOk,”VBS Message Box”

Page 12: Vbscript Introduction
Page 13: Vbscript Introduction
Page 14: Vbscript Introduction

Sample Code#1.

<HTML><HEAD><TITLE>VBSCRIPT LESSON 1</TITLE></HEAD><BODY><i>VBScript & HTML<br></i><SCRIPT LANGUAGE="VBSCRIPT">document.write "<B>HELLO FROM VBScript rendered HTML</B>"</SCRIPT></BODY></HTML>

Page 15: Vbscript Introduction

Sample Code#2.

<HTML><HEAD><TITLE>VBSCRIPT LESSON2</TITLE></HEAD><BODY><i>VBScript Message Box<br></i><SCRIPT LANGUAGE="VBSCRIPT">

MsgBox "Welcome to msgbox"</SCRIPT></BODY></HTML>

Page 16: Vbscript Introduction

Sample Code#3.

<HTML><HEAD><TITLE>VBSCRIPT LESSON 3</TITLE></HEAD><BODY><i>VBScript Message Box With Title and Button Types<br></i><SCRIPT LANGUAGE="VBSCRIPT">

MsgBox "Welcome to msgbox",vbYesNoCancel,"HELLO"</SCRIPT></BODY></HTML>

Page 17: Vbscript Introduction
Page 18: Vbscript Introduction

Sample Code#4.

<HTML><HEAD><TITLE>VBSCRIPT LESSON 4</TITLE></HEAD><BODY><i>VBScript Date Function<br></i><SCRIPT LANGUAGE="VBSCRIPT">

document.write "Today is " & Now</SCRIPT></BODY></HTML>

Page 19: Vbscript Introduction

Looping statements.

1. For – Next loop (The count loop)

2. For Each – Next (Collection Object picking)

3. While – Wend. (Top testing)

4. Do – loopa. Do – While/Until – loop. (top testing)

b. Do – loop – While/Until. (bottom testing)

Page 20: Vbscript Introduction

FOR-NEXT Loop.

Syntax:

FOR <count_var> = <initial_value> TO <final_value>

..

code

..

NEXT

Initial value should be <= final value.

Example:

FOR I = 1 TO 10

document.write “<br>Value of I = “ & I

NEXT

Page 21: Vbscript Introduction

FOR-NEXT step loop.

Syntax:

FOR <count_var> = <initial_value> TO <final_value> STEP n

..

code

..

NEXT

Initial value should be <= final value.

Example:

FOR I = 1 TO 10 STEP 2

document.write “<br>Value of I = “ & I

NEXT

Page 22: Vbscript Introduction

FOR-NEXT decrement loop.

Syntax:

FOR <count_var> = <initial_value> TO <final_value> STEP –n

..

code

..

NEXT

Initial value should be <= final value.

Example:

FOR I = 10 TO 1 STEP -1

document.write “<br>Value of I = “ & I

NEXT

Page 23: Vbscript Introduction

FOR-EACH-NEXT loop.

Syntax:

FOR EACH <object> IN <collection>

..

code

..

NEXT

Initial value should be <= final value.

Example:

FOR EACH n IN arr

document.write “<br>Element = “ & n

NEXT

Page 24: Vbscript Introduction

Sample Code#5.

<HTML>

<HEAD><TITLE>VBSCRIPT LESSON 5</TITLE></HEAD>

<BODY>

<i>VBScript renders counting 1 to 10 as HTML<br>

Odd numbers underlined and even numbers in bold<br>

</i>

<SCRIPT LANGUAGE="VBSCRIPT">

DIM i

FOR I = 1 TO 10

if (i mod 2 = 0) then

document.write "<b>"&i&"<br></b>"

else

document.write "<u>"&i&"<br></u>"

end if

NEXT

</SCRIPT>

</BODY>

</HTML>

Page 25: Vbscript Introduction

Sample Code#6.

• <HTML>• <HEAD><TITLE>VBSCRIPT LESSON 6</TITLE></HEAD>• <BODY>• <i>VBScript renders array elements 1 to 10 as HTML<br>• </i>• <SCRIPT LANGUAGE="VBSCRIPT">• DIM i• DIM arr(10)• FOR I = 1 TO 10• arr(I) = i*10• NEXT• FOR I = 1 TO 10• document.write "<b>"&arr(i)&"<br></b>"• NEXT• </SCRIPT>• </BODY>• </HTML>

Page 26: Vbscript Introduction

Sample Code#7.

• <HTML>• <HEAD><TITLE>VBSCRIPT LESSON 7</TITLE></HEAD>• <BODY>• <i>VBScript renders array elements 10 to 1 as HTML<br>• </i>• <SCRIPT LANGUAGE="VBSCRIPT">• DIM i• DIM arr(10)• FOR I = 1 TO 10• arr(I) = i*10• NEXT• FOR I = 10 TO 1 STEP -1• document.write "<b>"&arr(i)&"<br></b>"• NEXT• </SCRIPT>• </BODY>• </HTML>

Page 27: Vbscript Introduction

Sample Code#8.

• <HTML>• <HEAD><TITLE>VBSCRIPT LESSON 8</TITLE></HEAD>• <BODY>• <i>VBScript renders array elements 1 to 10 as HTML<br>• </i>• <SCRIPT LANGUAGE="VBSCRIPT">• DIM i• DIM arr(10)• FOR I = 1 TO 10• arr(I) = i*10• NEXT• FOR EACH N in arr• document.write "<b>"&N&"<br></b>"• NEXT• </SCRIPT>• </BODY>• </HTML>

Page 28: Vbscript Introduction

The WHILE-WEND loop.

Syntax:

WHILE <expression>

..

code

..

WEND

Loop goes on as long as the expression remains true.

Loop stops as soon as expression becomes false.

Example:

I = 1

WHILE I <= 10

document.write “<br> Value is = “ & I

WEND

Page 29: Vbscript Introduction

Sample Code#9.

<HTML><HEAD><TITLE>VBSCRIPT LESSON 9</TITLE></HEAD><BODY><i>VBScript renders array elements 1 to 10 as HTML using whileloop<br></i><SCRIPT LANGUAGE="VBSCRIPT">

Dim arr(10)FOR I = 1 TO 10

arr(I) = I * 10NEXTI = 1

WHILE I <= 10document.write "<br> Value of at "&I&“ = “&arr(I)

WEND</SCRIPT></BODY></HTML>

Page 30: Vbscript Introduction

Sample Code#10.

<HTML><HEAD><TITLE>VBSCRIPT LESSON 9</TITLE></HEAD><BODY><i>VBScript renders array elements 1 to 10 as HTML using whileloop<br></i><SCRIPT LANGUAGE="VBSCRIPT">

Dim arr(10)FOR I = 1 TO 10

arr(I) = I * 10NEXTI = 1

WHILE I <= 10document.write "<br> Value of at "&I&“ = “&arr(I)

WEND</SCRIPT></BODY></HTML>

Page 31: Vbscript Introduction

The DO-WHILE/UNTIL-LOOP loops.

1. DO-WHILE-LOOP loop.Syntax:

DO WHILE <expression>.. Code ..LOOPIt is a top-testing loop.Works same as a simple WHILE-WEND loop.Loop continues as long as expression is true and stops when it becomes false.If expression is false at the start loop wont start.

Example:I = 1DO WHILE I <= 10

document.write “<br> Value of I = “&II = I + 1

LOOP

Page 32: Vbscript Introduction

The DO-WHILE/UNTIL-LOOP loops.

2. DO-UNTIL-LOOP loop.Syntax:

DO UNTIL <expression>.. Code ..LOOPTop-testing loop.Works as long as expression is false.Stops as soon as expression becomes true.If expression is true at the start loop wont start.

Example:I = 1DO UNTIL I = 11

document.write “<br> Value of I = “&II = I + 1

LOOP

Page 33: Vbscript Introduction

The DO-LOOP-WHILE/UNTIL loops.

1. DO-LOOP-WHILE loop.Syntax:

DO.. Code ..LOOP WHILE <expression>Bottom-testing loop.Works as long as expression is true.Stops as soon as expression becomes false.Even if the expression is true at start loop will work at-least once.

Example:I = 1DO

document.write “<br> Value of I = “&II = I + 1

LOOP WHILE I < 11

Page 34: Vbscript Introduction

The DO-LOOP-WHILE/UNTIL loops.

2. DO-LOOP-UNTIL loop.Syntax:

DO.. Code ..LOOP UNTIL <expression>Bottom-testing loop.Works as long as expression is false.Stops as soon as expression becomes true.IF the expression is true at the start loop will work at-least once.

Example:I = 1DO

document.write “<br> Value of I = “&II = I + 1

LOOP UNTIL I = 11

Page 35: Vbscript Introduction
Page 36: Vbscript Introduction
Page 37: Vbscript Introduction
Page 38: Vbscript Introduction
Page 39: Vbscript Introduction
Page 40: Vbscript Introduction

EVENTS IN VBSCRIPT.

What are Events?Events are pieces of code that are run when an action is taken by the user. For instance, the web page could contain an event that would be run when a button is clicked. When the user clicks the button, the code is run. Events enable the web site to interact with the user, and are the tie that binds the code to the web page.

Page 41: Vbscript Introduction

EVENTS IN VBSCRIPT.

FOR EXAMPLE.<input type="button" value="Hello!" language="VBScript" OnClick="VBButtonClicked()">

<script language="VBScript">Sub VBButtonClicked()

 MsgBox("Hello!")End Sub

</script>

Page 42: Vbscript Introduction

EVENTS IN VBSCRIPT (Continued).

1. OnClick2. OnBlur.3. OnChange.4. OnFocus.5. OnMouseOver.6. OnMouseOut.7. OnMouseDown.8. OnMouseUp.9. OnMouseMove.10. OnKeyPress.11. OnDblClick.12. OnSelect.13. OnLoad.14. OnUnload.

Page 43: Vbscript Introduction

VBSCRIPT FUNCTION REFERENCE

Page 44: Vbscript Introduction

VBSCRIPT FUNCTION REFERENCE (Continued).

Page 45: Vbscript Introduction

VBSCRIPT FUNCTION REFERENCE (Continued).

Page 46: Vbscript Introduction

VBSCRIPT FUNCTION REFERENCE (Continued).

Page 47: Vbscript Introduction

VBSCRIPT FUNCTION REFERENCE (Continued).

Page 48: Vbscript Introduction

VBSCRIPT FUNCTION REFERENCE (Continued).

Page 49: Vbscript Introduction

VBSCRIPT FUNCTION REFERENCE (Continued).

Page 50: Vbscript Introduction

VBSCRIPT FUNCTION REFERENCE (Continued).


Recommended