I urge you not to mix scripting languages. The article you talked about has a headline called "Server Script Execution Order," which says:
... However, you are at the mercy of the IIS ASP execution order. For example, if you create a Script server and run it in IIS 4.0 you will find this execution order:
- Script in <SCRIPT> elements in underestimated languages.
- Inline script
- Script in <SCRIPT> elements in the default language
Keeping this in mind, here is how your testjs.asp Script is executed, comments indicate the order of execution:
<%@ Language="JavaScript" %> <script language="vbscript" runat="server"> '' #1 Sub VBTestFunction(Message) Response.Write "VBTestFunction: " & Message End Sub </script> <script language="javascript" runat="server"> </script> <script language="javascript" runat="server"> </script> <script language="vbscript" runat="server"> '' #2 Call VBTestFunction("from vbscript") Call JSTestFunction("from vbscript") </script>
Notice the line that causes the error:
Call JSTestFunction("from vbscript")
Its execution order is # 2; at this point, the JSTestFunction function JSTestFunction not defined (it is defined later in execution order).
Now for the testvbs.asp file:
<%@ Language="VBScript" %> <script language="vbscript" runat="server"> '' 3 Sub VBTestFunction(Message) Response.Write "VBTestFunction: " & Message End Sub </script> <script language="javascript" runat="server"> </script> <script language="javascript" runat="server"> </script> <script language="vbscript" runat="server"> '' 4 Call VBTestFunction("from vbscript") Call JSTestFunction("from vbscript") </script>
Error line:
VBTestFunction("from javascript");
Again, the VBTestFunction is called before it is defined. The solution is to try not to mix scripting languages. If absolutely necessary, edit the order of your scripts.
Edit - Example
If you set @ Language="JavaScript" , then this code should work as expected:
<script language="vbscript" runat="server"> Sub VBTestFunction(Message) Response.Write "VBTestFunction: " & Message End Sub </script> <% function JSTestFunction(Message) { Response.Write("JSTestFunction: " + Message); } %> <%@ Language="JavaScript" %> <% // at this point, both functions are available VBTestFunction("from inline JavaScript"); JSTestFunction("from inline JavaScript"); %>
If you want to use @ Language="VBScript" , you need to reorder all the code:
<script language="javascript" runat="server"> function JSTestFunction(Message) { Response.Write("JSTestFunction: " + Message); } </script> <% Sub VBTestFunction(Message) Response.Write "VBTestFunction: " & Message End Sub %> <%@ Language="VBScript" %> <% ' at this point, both functions are available VBTestFunction("from inline VBScript") JSTestFunction("from inline VBScript") %>