Calling Global shared sub not working

Discussion in 'ASP .Net' started by tshad, Feb 23, 2005.

  1. tshad

    tshad Guest

    I just put this together from O'Reillys book (with much of the code stripped
    out).

    Global.asax:
    ******************************************
    <%@ Application Language="VB" %>

    <script runat="server">

    public shared sub WriteFile(strText as string)
    response.write("<br>inside WriteFile strText = " & strText & "<br>")
    end sub

    </script>
    ******************************************

    testglobal.aspx
    ******************************************
    <%@ Page Language="VB" debug="true" ContentType="text/html"
    ResponseEncoding="iso-8859-1" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <script runat="server">

    sub Page_Load(sender as Object, e as EventArgs)
    Global.WriteFile("This is a test")
    end sub

    <html>
    <body>
    </body>
    </html>
    ******************************************

    It is obviously calling sub, but I don't understand the error:
    ************************************************************
    Compiler Error Message: BC30369: Cannot refer to an instance member of a
    class from within a shared method or shared member initializer without an
    explicit instance of the class.

    Source Error:

    Line 4:
    Line 5: public shared sub WriteFile(strText as string)
    Line 6: response.write("<br>inside WriteFile strText = " & strText &
    "<br>")
    Line 7: end sub
    Line 8:
    ***********************************************************************

    Is it the response.write that is causing the error?

    Thanks,

    Tom
     
    tshad, Feb 23, 2005
    #1
    1. Advertising

  2. tshad

    Oleg Ogurok Guest

    Don't make it shared. You can't call a reference object from a shared
    method.

    -Oleg.

    "tshad" <> wrote in message
    news:...
    >I just put this together from O'Reillys book (with much of the code
    >stripped out).
    >
    > Global.asax:
    > ******************************************
    > <%@ Application Language="VB" %>
    >
    > <script runat="server">
    >
    > public shared sub WriteFile(strText as string)
    > response.write("<br>inside WriteFile strText = " & strText & "<br>")
    > end sub
    >
    > </script>
    > ******************************************
    >
    > testglobal.aspx
    > ******************************************
    > <%@ Page Language="VB" debug="true" ContentType="text/html"
    > ResponseEncoding="iso-8859-1" %>
    > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    >
    > <script runat="server">
    >
    > sub Page_Load(sender as Object, e as EventArgs)
    > Global.WriteFile("This is a test")
    > end sub
    >
    > <html>
    > <body>
    > </body>
    > </html>
    > ******************************************
    >
    > It is obviously calling sub, but I don't understand the error:
    > ************************************************************
    > Compiler Error Message: BC30369: Cannot refer to an instance member of a
    > class from within a shared method or shared member initializer without an
    > explicit instance of the class.
    >
    > Source Error:
    >
    > Line 4:
    > Line 5: public shared sub WriteFile(strText as string)
    > Line 6: response.write("<br>inside WriteFile strText = " & strText &
    > "<br>")
    > Line 7: end sub
    > Line 8:
    > ***********************************************************************
    >
    > Is it the response.write that is causing the error?
    >
    > Thanks,
    >
    > Tom
    >
    >
    >
     
    Oleg Ogurok, Feb 25, 2005
    #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. Imran Aziz
    Replies:
    1
    Views:
    559
    Stefan
    Aug 22, 2005
  2. Ben
    Replies:
    2
    Views:
    954
  3. Replies:
    1
    Views:
    1,325
    santosh
    Jul 15, 2008
  4. Lawrence D'Oliveiro

    Death To Sub-Sub-Sub-Directories!

    Lawrence D'Oliveiro, May 5, 2011, in forum: Java
    Replies:
    92
    Views:
    2,165
    Lawrence D'Oliveiro
    May 20, 2011
  5. Richard Gration

    Legitimate use of calling a sub as &sub

    Richard Gration, Feb 23, 2005, in forum: Perl Misc
    Replies:
    1
    Views:
    135
    Brian McCauley
    Feb 23, 2005
Loading...

Share This Page