CIS 375Web App Dev II VBScript Introduction to
CIS 375—Web App Dev II VBScript
Introduction to VBScript n n VBScript is a light version of MS’s ______. Example: <html> <body> <script type="text/vbscript"> document. write("Hello from VBScript!") </script> </body> </html> n Handling older browsers: <script type="text/vbscript"> <!– some statements --> </script> 2
VBScript…Where To n n VBScript ______ are usually located in the head section of a web page. VBScript code can also be located in the body section. <html> <head> <script type="text/vbscript"> some statements </script> </head> <body> <script type="text/vbscript"> some statements </script> </body> </html> 3
Variables n Use “option explicit” to force yourself to declare variables before using them: option explicit dim name=“Richard Johnson” n A VBScript “procedure” is like a Java. Script “_____. ” Procedure variables have _____ scope. An array with _______ elements: dim names (2) Assigning a value: names(0)=“John Doe” n A two-dimensional array with 5 rows and 7 columns: n n n dim table (5, 7) 4
Procedures n The Sub procedure can perform actions, but does not _______ a value. sub my. Sub() msgbox("This is a sub procedure") end sub n n Calling a Sub procedure: call my. Sub() The Function procedure can return a value. function my. Function() my. Function = "BLUE" end function n Calling a Function: document. write(“The sky is “ & my. Function()) 5
If…Then…Elseif if payment="Cash" then msgbox "You are going to pay cash!" elseif payment="Visa" then msgbox "You are going to pay with Visa. " elseif payment="Am. Ex" then msgbox "You are going to pay with American Express. " else msgbox "Unknown method of payment. " end If 6
Select Case select case payment case "Cash" msgbox "You are case "Visa" msgbox "You are case "Am. Ex" msgbox "You are Express" case Else msgbox "Unknown end select going to pay cash" going to pay with visa" going to pay with American method of payment" 7
For…Next for i = 0 to 6 Step 2 document. write("The number is " & i & " ") next For Each…Next dim names(2) names(0)="Tove" names(1)="Jani" names(2)="Hege" For Each x in names document. write(x & " ") Next 8
Do…While i=0 do while i < 10 document. write(i & " ") i=i+1 loop Exit a Do…Loop Do Until i=10 i=i-1 If i<10 Then Exit Do Loop 9
Examples n Look at many other VBScript examples 10
- Slides: 10