views:

55

answers:

1

I'm planning on writting some new code for a legacy ASP application in Python, and I ran into some odd behavior. If I write a function in python I can easily call it from a VBScript block. However, if I try to call a function defined in VBScript from python, I get an error:

Python ActiveX Scripting Engine error '80020009'

Traceback (most recent call last): File "<Script Block >", line 3, in <module> PrintVBS() NameError: name 'PrintVBS' is not defined

/test.asp, line 20

Here is a quick example demonstrating the problem:

<script language="Python" runat="server">
def PrintPython():
    Response.Write( "I'm from python<br>" )
</script>

<script language="vbscript" runat="server">
Sub PrintVBS()
    Response.Write( "I'm from VBScript<br>" )
End Sub
</script>

<script language="vbscript" runat="server">
PrintVBS()
PrintPython()
</script>


<script language="python" runat="server">
PrintPython() # code is fine up to here, 
PrintVBS() # no error if you comment this line
</script>

Does anyone have any insight into this behavior? Any workarounds?

Note, I am aware that I could throw my vbscript code in a WSC file, but I find them a royal pain to work with, and I'd like to avoid that if at all possible.

+2  A: 

It probably has to do with the order in which the script tags are processed.

In this case, it seems that the script tags containing python code are processed first, and then the ones with vbscript. The result is that you are trying to call PrintVBS() before it is available.

If you would change the default language to python, you would probably get the reverse error.

Steven
This is definitely what is going on. Based on this, I found that the order of the script tags is irrelevant, and changing the <%@ Language %> tag does control the order of execution. Strangely, if I use <%@ Language = "Python" %> I can not call across languages in either direction.
Tristan Havelick