Visual Basic, Scripting Edition, is yet another implementation of Microsoft Visual Basic; this version allows developers to write programs—known as scripts—inside an HTML document. Since this is a book about Java, I won’t spend any time teaching you how to script with Visual Basic, Scripting Edition.
A Visual Basic, Scripting Edition, program can call any public member of a Java applet. For example, I could create a Java class.
public class Alarm extends Applet
{
private int m_nVolume;
public void setVolume(int v)
{
m_nVolume = v;
}
}
I could then include the applet in an HTML document.
<APPLET CODE="Alarm.class" IS=ringer>
Then I could call setVolume from a script.
<SCRIPT language="VBScript">
<!--
Sub setLowVolume
document.ringer.setVolume 10
End Sub
Sub setHighVolume
document.ringer.setVolume 100
End Sub
-->
</SCRIPT>
The term document identifies the location of the ringer object, which is part of the web page. What I’ve done above isn’t COM programming; I’m simply using Visual Basic, Scripting Edition, to communicate between the web page and the applet. But as you’ll see, this mechanism is quite useful in connecting Java applets to ActiveX controls.