Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Calling Global shared sub not working

Reply
Thread Tools

Calling Global shared sub not working

 
 
tshad
Guest
Posts: n/a
 
      02-23-2005
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



 
Reply With Quote
 
 
 
 
Oleg Ogurok
Guest
Posts: n/a
 
      02-25-2005
Don't make it shared. You can't call a reference object from a shared
method.

-Oleg.

"tshad" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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
>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Death To Sub-Sub-Sub-Directories! Lawrence D'Oliveiro Java 92 05-20-2011 06:50 AM
Recognising Sub-Items and sub-sub items using xslt Ben XML 2 09-19-2007 09:35 AM
Question about sub calling other sub Martin Kissner Perl Misc 8 03-09-2006 06:21 PM
Global Shared functions, shared variables Imran Aziz ASP .Net 1 08-22-2005 06:43 PM
Legitimate use of calling a sub as &sub Richard Gration Perl Misc 1 02-23-2005 05:43 PM



Advertisments