Calling Global shared sub not working

T

tshad

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
 
O

Oleg Ogurok

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

-Oleg.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top