Presentation is loading. Please wait.

Presentation is loading. Please wait.

VBScript Examples. Visual Basic & VBScript Visual Basic Visual Basic Stand-alone (compiled or interpreted) Stand-alone (compiled or interpreted) Variables.

Similar presentations


Presentation on theme: "VBScript Examples. Visual Basic & VBScript Visual Basic Visual Basic Stand-alone (compiled or interpreted) Stand-alone (compiled or interpreted) Variables."— Presentation transcript:

1 VBScript Examples

2 Visual Basic & VBScript Visual Basic Visual Basic Stand-alone (compiled or interpreted) Stand-alone (compiled or interpreted) Variables are typed Variables are typed VBScript Embedded in a Web page and executed by browser Variables can be associated with any type Uses most program structures available in VB, including loops and decisions

3 VBScript Examples Greeting (printing to message box) Greeting (printing to message box) Greeting 2 (printing to current window) Greeting 2 (printing to current window) Speed Check (Dicision) Speed Check (Dicision) Blast Off! (FOR loop) Blast Off! (FOR loop) Varying Font (FOR loop) Varying Font (FOR loop) Speed Check 2 (event handler) Speed Check 2 (event handler) Speed Check 2B (alternate code) Speed Check 2B (alternate code) Get User Input Get User Input Heart Beat (calculation in event handler) Heart Beat (calculation in event handler) Heart Beat 2 (arguments to event handler) Heart Beat 2 (arguments to event handler)

4 Greeting VBScript Demo VBScript Demo Try it.

5 Greeting 2 VBScript Demo VBScript Demo Try it.

6 Speed Check Dim yourSpeed Dim diff Dim message const maxSpeed = 50 yourSpeed = 60 message = "Your Speed is " & yourSpeed & " mph." diff = yourSpeed - maxSpeed If diff > 0 Then message = message & " You are speeding by " & diff & " mph." Else message = message & "You are under the speed limit." End If MsgBox message Try it. Speed Check (Decision)

7 Blast Off! (For Loop) VBScript Demo For Loop Demo Dim num For num = 10 To 1 Step -1 document.write(num & "!" & " ") Next document.write("Blast Off!") Try it.

8 Varying Font (For Loop)... For Loop Demo Dim num For num = 1 To 6 document.write(" ") document.write(" This sentence was” & _ “ generated by VBScript. ") document.write(" ") Next Try it.

9 Events Event: An action by the user--e.g., mouse-click, mouse- move, etc.—that triggers execution of a code known as event handler Event: An action by the user--e.g., mouse-click, mouse- move, etc.—that triggers execution of a code known as event handler Event Handler: Piece of programming code, written in VBScript, Javascript, Java, etc., allowing the page to react to user input Event Handler: Piece of programming code, written in VBScript, Javascript, Java, etc., allowing the page to react to user input

10 Event Examples Event Name Example onClick Mouse button clicked on textbox onDblClick Button double-clicked on textbox onMouseMove Mouse is moved onMouseOut Mouse pointer leaves image area onMouseOver Mouse pointer first enters image area onLoad Web page is loaded

11 onClick Demo Enter your name. { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/13/4176570/slides/slide_11.jpg", "name": " onClick Demo Enter your name.", "description": "

12 Subprogram Greeting … … … …", "description": "Subprogram Greeting … …", "width": "800" }

13 ... Speed Check Dim yourSpeed Dim diff Dim message const maxSpeed = 50 yourSpeed = 60 message = "Your Speed is " & yourSpeed & " mph." diff = yourSpeed - maxSpeed If diff > 0 Then message = message & " You are speeding by " & diff & " mph." Else message = message & "You are under the speed limit." End If MsgBox message Try it. (Recall) Speed Check

14 Speed Check 2 (Event Handler) VBScript Demo Speed Check Try it.

15 Speed Check 2 (Event Handler)

16 Speed Check 2B (Alternate Code) VBScript Demo Speed Check Try it.

17 Get User Input... Code for GreetUser() goes here Get User Information Demo Please enter your name. Please enter your age. Try it.

18 GreetUser() How Many Times Have My Heart Beaten So Far? Please enter your age. Try it.

22 Heart Beat (Calculaton)

23 Heart Beat 2 (Using argument) VBScript Calculaton Demo How Many Times Have My Heart Beaten So Far? Please enter your age. Try it.

24 Heart Beat 2 (Using argument)

25 onMouseOut (Using argument) VBScript Calculaton Demo onMouseOver & onMouseOut Demo Hover the cursor over the text box, then move it away. Try it.

26 onMouseOut (Using argument) …

27 Three Buttons & One Subprocedure Changing BG Color with One Subprocedure

28 Three Buttons & One Subprocedure …

29 Your Turn Write an HTML page in which: Write an HTML page in which: The user is asked to input in a form one’s name. The user is asked to input in a form one’s name. When a button is clicked, a greeting which is appropriate for the current time—”Good morning,” Good afternoon,” or “Good evening”—is displayed along with the user’s name. When a button is clicked, a greeting which is appropriate for the current time—”Good morning,” Good afternoon,” or “Good evening”—is displayed along with the user’s name.

30 Your Turn (2) Write an HTML page in which: Write an HTML page in which: The user is asked to input in a form one’s name and a purchase price at a gift shop. The user is asked to input in a form one’s name and a purchase price at a gift shop. When a button is clicked, the luxury tax on the price is calculated according to the following formula: When a button is clicked, the luxury tax on the price is calculated according to the following formula: For price < $100, tax rate = 0% For price < $100, tax rate = 0% For price >= $100, tax rate = 6% For price >= $100, tax rate = 6% A message box displays the user’s name, price, tax, and the total. A message box displays the user’s name, price, tax, and the total.


Download ppt "VBScript Examples. Visual Basic & VBScript Visual Basic Visual Basic Stand-alone (compiled or interpreted) Stand-alone (compiled or interpreted) Variables."

Similar presentations


Ads by Google