Welcome to ITM Web100 Training Program


Lesson 8

VBScript and ActiveX Controls

Lets see how we can make VBScript to work for us.
Here are few details you need to know.


Write a procedure and call it to Print out HTML text



The code:

<HTML>
<HEAD><TITLE>VBScript procedure</TITLE></HEAD>

<SCRIPT LANGUAGE="VBSCRIPT">
<!--
  Sub MyInfo()
    Document.write "<H1>Welcome to ITM's home page</H1>"
    Document.write "<P>ITM likes money and ITM is here to make money</P>"
    Document.write "<P>Send ITM a student and you can also make some money</P>"
  End Sub
-->
</SCRIPT>

<BODY BGCOLOR="#FFFFFF">

<SCRIPT LANGUAGE="VBSCRIPT">
<!--
  Call MyInfo
-->
</SCRIPT>

</BODY>

</HTML>


Yet another VBScript feature
Random messages Generate a random welcome message every time a user visits the page.

Random messages





The code:

<HTML>
<HEAD><TITLE>Random messages</TITLE></HEAD>

<SCRIPT LANGUAGE="VBSCRIPT">
<!--
  Function RandomGreeting()
    Dim Greeting(5), Quote

    Randomize

    Greeting(0) = "Hello there!"
    Greeting(1) = "Welcome!"
    Greeting(2) = "Namaskaram, Malli-Randi!"
    Greeting(3) = "Sasriyakaal!"
    Greeting(4) = "Hi!"

    Quote = Int(Rnd() * 5)
    RandomGreeting = Greeting(Quote)
  End Function
-->
</SCRIPT>

<BODY BGCOLOR="#FFFFFF">

<SCRIPT LANGUAGE="VBSCRIPT">
<!--
  Document.write RandomGreeting
-->
</SCRIPT>

</BODY>

</HTML>

Case by case decisions
Use the Select Case structure to choose from a large number of possible choices.

Case by case decisions





The code:

<HTML>
<HEAD><TITLE>Case by case decisions</TITLE></HEAD>

<BODY BGCOLOR="#FFFFFF">

<SCRIPT LANGUAGE="VBSCRIPT">
<!--
  Document.write "It's " & MonthName(Month(Date)) & "...<BR>"

  Select Case MonthName(Month(Date))
    Case "January"
      Document.write "The coldest month of all"
    Case "February"
      Document.write "Will you be my valentine"
    Case "March"
      Document.write "Now that I have you I can MARCH Ahead"
    Case "April"
      Document.write "April Fools!"
    Case "May"
      Document.write "Ring around the rosey..."
    Case "June"
      Document.write "Monsoon time for us Indians!"
    Case "July"
      Document.write "Celebrate the fouth of July"
    Case "August"
      Document.write "It's the Windows 95 Anniversary"
    Case "September"
      Document.write "Back to School"
    Case "October"
      Document.write "Happy Halloween"
    Case "November"
      Document.write "Happy Thanksgiving"
    Case "December"
      Document.write "Happy Christmas"
  End Select
-->
</SCRIPT>

</BODY>

</HTML>

ActiveX Controls

A note about ActiveX controls Microsoft has abandonded them . If you've dealt with Microsoft before, you'll understand why this happened: ActiveX controls were the flavor the month when IE 3.0 came out. Microsoft created brand awareness, promoted the heck out of it, feeded developers with all the info they needed.

Then they abandoned them.

The ActiveX control as we know it (that is, you and I) is dead.

Why is that, you ask? Well, something better came along, as it often does, and like the ActiveX control before it, this new technology is also very much Microsoft-specific. It's called Dynamic HTML, a valiant attempt at melding scripting (either VBScript or JavaScript). Using Dynamic HTML, you can do just about everything you ever did with ActiveX controls . In fact, Dynamic HTML is the Next Big Thing if you're a VBScripter.

For those of you still interested in knowing how to interact with ActiveX controls, we need to talk about ActiveX Control Pad.

Scripting Object Model


Window object reference

Property What it is
defaultStatus The default text that will appear in the current window's status bar.
document The Document object for the current window.
frames The list of frames for the current window.
history The History object for the current window.
location The Location object for the current window.
name The name of the current window.
navigator The Navigator object for the current window.
opener The Window object that opened the current window.
parent The frame that contains the current window.
self The Window object of the current window.
status Used to set the text in the current window's status bar.
top The topmost window's Window object.



Method What it is
alert Displays a dialog box with an alert message.
clearTimeout Clears a particular timer.
close Closes the current browser window.
confirm Displays a dialog box with OK and Cancel choices.
navigate Navigates the window to a new URL.
open Opens a new browser window.
prompt Prompts the user for input using a dialog box.
setTimeout Calls a function after a period of time has elapsed.



Event When it occurs
onLoad Occurs when the page in the window has fully loaded.
onUnload Occurs when the page in the window closes.

Further Info about Scriting Object Model