NextPreviousUsing Visual Basic ScriptHow VBScript Looks in HTML


The <SCRIPT> Tag
VBScript code goes in an HTML page inside paired <SCRIPT> tags. For example, a procedure to test a delivery date might appear as follows:

<SCRIPT LANGUAGE="VBScript"> 
<!--
   Function CanDeliver(Dt)
      CanDeliver = (CDate(Dt) - Now()) > 2
   End Function
-->
</SCRIPT>
Beginning and ending <SCRIPT> tags surround the code. Notice that the LANGUAGE attribute indicates the scripting language. You need to specify the language since Microsoft Internet Explorer version 3.0 can use other scripting languages. In addition, notice that the CanDeliver function is embedded in comment tags (<!-- and -->). This prevents browsers that don't understand the <SCRIPT> tag from displaying the code.

Since the example is a general function - it isn't tied to any particular form control - you can include it in the HEAD section of the page:


<HTML>
<HEAD>
<TITLE>Place Your Order</TITLE>
<SCRIPT LANGUAGE="VBScript">
<!--
   Function CanDeliver(Dt)
      CanDeliver = (CDate(Dt) - Now()) > 2
   End Function
-->
</SCRIPT>
</HEAD>
<BODY>
...
You can use procedures in code anywhere in a page. You can put procedures in both the BODY and HEAD sections. However, you may want to put all procedures in the HEAD section in order to keep all the code together.

Now, let's look at some elements of the language.




NextPreviousUsing Visual Basic Script© 1996 by Microsoft Corporation.