Transcript

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.

The Message Box.

Syntax:MsgBox prompt, buttons, title

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

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>

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>

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>

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>

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)

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

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

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

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

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>

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>

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>

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>

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

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>

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>

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

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

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

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

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.

EVENTS IN VBSCRIPT.

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

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

 MsgBox("Hello!")End Sub

</script>

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.

VBSCRIPT FUNCTION REFERENCE

VBSCRIPT FUNCTION REFERENCE (Continued).

VBSCRIPT FUNCTION REFERENCE (Continued).

VBSCRIPT FUNCTION REFERENCE (Continued).

VBSCRIPT FUNCTION REFERENCE (Continued).

VBSCRIPT FUNCTION REFERENCE (Continued).

VBSCRIPT FUNCTION REFERENCE (Continued).

VBSCRIPT FUNCTION REFERENCE (Continued).

top related