|
Join the Discussion
|
What are you using VBScript for? Tell us how it's working for you in the message board.
Discussion Forum
|
|
 |
The Two Button Form looks like this in the IE 6 web browser.
Programming the "Two Button Form" in VBScript is actually more an example of DHTML (Dynamic HTML) than it is Visual Basic. The actual VBScript code is almost identical to the same code in VB 6. Here's the VBScript code:
Sub buttonA_onclick
MsgBox("Button A was clicked")
End Sub
Sub buttonB_onclick
MsgBox("Button B was clicked")
End Sub
The Compatibility Conundrum
As the previous page noted, execution of this code depends on a suitable 'host'. IE works! IE will also host JavaScript. Netscape, on the other hand, will host JavaScript but it will not host VBScript. For this reason, the standard procedure for most coders today is to use Javascript as the client scripting language rather than VBScript even in true blue Microsoft shops. If you can guarantee what type of browser will be used (for example, in a corporate Intranet) or if you just don't care, go ahead and use VBScript anyway.
As it turns out, this isn't as much of a problem as it used to be. Whether you agree with it or not, IE has pretty much taken over the entire browser market.
The Complete HTML Source
In any case, this remains a good way to introduce VBScript coding. Let's look at the entire HTML file.
Things to notice:
- The entire script is surrounded by "Comment" marks to keep it from being interpreted as part of the text in the page. The browser host that executes the script reads past these marks.
- The LANGUAGE=vbscript attribute in the SCRIPT tag. This tells the browser which host script interpreter to use.
- The INPUT tag. This is the DHTML tag that links the script code to a browser object.
- The script code is in the HEAD section of the HTML rather than the BODY. When the browser finds the reference in the INPUT tag in the body, the code in the HEAD has already been read.
- The names of the script subroutines are the same as in Visual Basic: object name, underscore character, event.
<html>
<head>
<title>Two Button Form</title>
<SCRIPT ID=clientEventHandlersVBS LANGUAGE=vbscript>
<!--
Sub buttonA_onclick
MsgBox("Button A was clicked")
End Sub
Sub buttonB_onclick
MsgBox("Button B was clicked")
End Sub
-->
</SCRIPT>
</head>
<body>
<INPUT type="button" value="A" id=buttonA name=buttonA>
<INPUT type="button" value="B" id=buttonB name=buttonB>
</body>
</html>
Start Page >
VBScript -- The 'Worker Bee'
|