Partager via


Adding VBScript Code to an HTML Page (Windows Embedded CE 6.0)

1/6/2010

To add VBScript code to an HTML page, enclose the script in a pair of <SCRIPT> tags, using either the TYPE attribute or the LANGUAGE attribute to specify the scripting language. You can put VBScript code blocks anywhere on an HTML page. In fact, it is a good practice to put all general-purpose scripting code (that is, script that is not tied to a particular form control) in the HEAD section. This ensures that script will already have been read and decoded before it is called from the body of the HTML page.

The following code example shows a VBScript procedure to test a delivery.

<SCRIPT TYPE="text/VBScript"> 
'Or: <SCRIPT LANGUAGE="VBScript" 
<!--
   Function CanDeliver(Dt)
      CanDeliver = (CDate(Dt) - Now()) > 2
   End Function
-->
</SCRIPT>

Be aware that the CanDeliver function is embedded in comment tags (<!-- and -->). This prevents browsers that do not support the <SCRIPT> tag from displaying the code.

A script that is likely to be called multiple times while a page is loaded will usually use a Function or Sub routine. This is then called from outside the script. Scripts that are called only one time when a page is loaded, for example to initialize data or change the look of a page, do not use routines.

If you have a script that executes in response to a specific event in a particular form, you may prefer to embed the script in the form block. The following example uses VBScript code to respond to a button click in a form.

<HTML>
<HEAD>
<TITLE>Test Button Events</TITLE>
</HEAD>
<BODY>
<FORM NAME="Form1">
   <INPUT TYPE="Button" NAME="Button1" VALUE="Click">
   <SCRIPT FOR="Button1" EVENT="onClick" LANGUAGE="VBScript">
      MsgBox "Button Pressed!"
   </SCRIPT>
</FORM>
</BODY>
</HTML>

See Also

Other Resources

VBScript Application Development