|
APG Script Syntax Reference |
|
See Also: |
Delimits a script block.
<SCRIPT RUNAT=APGen
[ LANGUAGE= JScript | VBScript | others ] >
script block
</SCRIPT>
| Attribute | Description | ||||||
| RUNAT=APGen | Necessary. Specifies that this script block should be run by APGen. If this attribute is omitted, the script is considered content, and will be written to the output file. | ||||||
| LANGUAGE= JScript | VBScript | others |
Optional. Specifies the scripting language for this block. If not specified, the default scripting language is used. The default scripting language is discussed in the @LANGUAGE topic.
|
This element is a block element, meaning the </SCRIPT> tag must be used to specify the end of the script block.
The <SCRIPT RUNAT=APGen> ... </SCRIPT> sequence is functionally equivalent to APG script brackets, <%#... #%>. The only difference is that the <SCRIPT> tag can be used to set the script language for the script block.
Multiple script languages can be mixed within an APG script. For more information, see Mixing Script Languages.
Using the LANGUAGE= attribute within a <SCRIPT> tag sets the script language for the script block. After the closing </SCRIPT>tag, the default scripting language is used.
The scripting language cannot be changed in the middle of a function, procedure, or any sort of language construct (such as for .. next, if .. then .. else, etc.). Doing so will cause a compilation error, and the script will not be run.
A key point when mixing script languages is that execution of global code may not occur in a predictable manner. This is consistent with the ASP and IE implementation, and is related to using independent script engines. The best way to avoid any problems is to write all global code using a single language. <SCRIPT> fragments that use the LANGUAGE= attribute should contain functions, and no global code or content. For more information, see Mixing Script Languages.
Below is an APG script (hello.apg) that uses the <SCRIPT> tag.
<SCRIPT RUNAT=APGen>
' This is VBScript, the default language
Output.Filename = "hello.htm"
</SCRIPT>
<SCRIPT RUNAT=APGen LANGUAGE=JScript>
// This is JScript
// Note that, since we're using a different LANGUAGE,
// there is no global code here, only a function.
function RenderHellos()
{
var i;
for (i=1; i<=5; ++i)
Output.Write("<P>Hello World!</P>\r\n");
}
</SCRIPT>
<!-- Render the Page Content -->
<HTML><BODY>
<SCRIPT
RUNAT=APGen>
' This is VBScript, but we call a JScript function
RenderHellos
</SCRIPT>
</BODY></HTML>
This script creates the following output file (hello.htm):
<!-- Render the Page Content -->
<HTML><BODY>
<P>Hello World!</P>
<P>Hello World!</P>
<P>Hello World!</P>
<P>Hello World!</P>
<P>Hello World!</P>
</BODY></HTML>