HELP: ASP JScript & VBScript interoperability

Discussion in 'ASP General' started by Andrew Wan, Jun 15, 2007.

  1. Andrew Wan

    Andrew Wan Guest

    How can VBScript code access JScript code variables in the same ASP page?

    <SCRIPT LANGAUGE="VBScript">
    Dim a
    a = 10
    </SCRIPT>
    <SCRIPT LANGUAGE="JScript">
    Response.Write(a);
    </SCRIPT>

    Also, is this valid JScript code because ASP hasn't complained.

    <SCRIPT LANGUAGE="JScript">
    function Section(a, b, c, d) {
    this.a = a;
    this.memFunction = function() {
    this.a = this.a + 1;
    }
    }
    </SCRIPT>

    Basically it's like JScript's way of declaring classes.

    How can VBScript code create a Section object?

    <SCRIPT LANGUAGE="VBScript">
    Dim obj
    obj = new Section 'Error, says cannot find Section
    obj = new Section() 'Error again
    obj = new Section(1, 2, 3, 4) 'Error again
    </SCRIPT>


    Also, is it possible to nest <SCRIPT> tag inside <% %>? Like:

    <%
    'Some VBScript code
    Class AClass
    Private a
    Function b()
    End Function
    %>
    <!-- #INCLUDE VIRTUAL="JScript.asp" -->
    <%
    End Class
    %>

    where JScript.asp has:

    <SCRIPT LANGUAGE="JScript">
    function Section() {
    function Section2() {
    }
    }
    </SCRIPT>

    ASP didn't complain. But couldn't test whether the JScript functions Section
    were member functions of the VBScript AClass.
     
    Andrew Wan, Jun 15, 2007
    #1
    1. Advertising

  2. Re: ASP JScript & VBScript interoperability

    "Andrew Wan" <> wrote in message
    news:...
    > How can VBScript code access JScript code variables in the same ASP page?
    >
    > <SCRIPT LANGAUGE="VBScript">
    > Dim a
    > a = 10
    > </SCRIPT>
    > <SCRIPT LANGUAGE="JScript">
    > Response.Write(a);
    > </SCRIPT>
    >
    > Also, is this valid JScript code because ASP hasn't complained.


    It won't because without a runat="server" attribute on the script element
    the above is simply treated as content and sent to the client. The client
    should've complained that Response is undefined.

    To answer your question variables and functions declared at global scope are
    accessible across the script boundaries.



    >
    > <SCRIPT LANGUAGE="JScript">
    > function Section(a, b, c, d) {
    > this.a = a;
    > this.memFunction = function() {
    > this.a = this.a + 1;
    > }
    > }
    > </SCRIPT>
    >
    > Basically it's like JScript's way of declaring classes.


    Yeah but it's very JScript and is completely alien to VBScript.

    >
    > How can VBScript code create a Section object?
    >
    > <SCRIPT LANGUAGE="VBScript">
    > Dim obj
    > obj = new Section 'Error, says cannot find Section
    > obj = new Section() 'Error again
    > obj = new Section(1, 2, 3, 4) 'Error again
    > </SCRIPT>


    You need to create a factory function in the JScript:-

    function newSection(a, b, c, d)
    {
    return new Section(a, b, c, d)
    }

    Now VBScript can use:-

    Set obj = newSection(1,2,3,4)

    >
    >
    > Also, is it possible to nest <SCRIPT> tag inside <% %>? Like:
    >
    > <%
    > 'Some VBScript code
    > Class AClass
    > Private a
    > Function b()
    > End Function
    > %>
    > <!-- #INCLUDE VIRTUAL="JScript.asp" -->
    > <%
    > End Class
    > %>
    >
    > where JScript.asp has:
    >
    > <SCRIPT LANGUAGE="JScript">
    > function Section() {
    > function Section2() {
    > }
    > }
    > </SCRIPT>


    No do it the other way around:-

    Have a JScript.js file

    then add this outside <% %> :-

    <script src="test.js" runat="server" language="JScript" ></script>

    Note it only makes sense to use this a function library, in-line code isn't
    much use apart from code that may help create objects.

    >
    > ASP didn't complain. But couldn't test whether the JScript functions

    Section
    > were member functions of the VBScript AClass.
    >
    >


    Again the runat attribute was missing.
     
    Anthony Jones, Jun 15, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon Maz
    Replies:
    4
    Views:
    1,318
    Jon Maz
    Sep 9, 2004
  2. Maxwell2006
    Replies:
    5
    Views:
    2,438
    Steven Cheng[MSFT]
    Mar 7, 2006
  3. Harag

    ASP VBscript vs Jscript

    Harag, Dec 26, 2003, in forum: ASP General
    Replies:
    15
    Views:
    303
    Dave Anderson
    Dec 29, 2003
  4. John Bentley
    Replies:
    14
    Views:
    387
    Jim Ley
    Feb 5, 2004
  5. Replies:
    1
    Views:
    126
Loading...

Share This Page