Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

"non-shared member requires an object reference" error within class

0 views
Skip to first unread message

David Gardiner

unread,
Jul 10, 2001, 4:01:52 AM7/10/01
to
Is there a restriction referring to the Request, Response and Server properties from within a class method?
 
I'm trying to get a VB Class to compile that refers to Request.QueryString, but the compilation fails with the error:
 
BC30469: This reference to a non-shared member requires an object reference, and none is supplied
 
Here's an example of a method that is failing:
Line 244:	Private Sub NoFrames
Line 245:
Line 246: Response.Write("<noframes><body><p>This page uses frames, but your browser doesn't support them.</p></body></noframes>")
Line 247:
Line 248: End Sub
 
Any help appreciated,
-david

--
David Gardiner <>< Senior Programmer with UniSAnet Project.
Flexible Learning Centre, Underdale Campus, University of South Australia
Email:
david.g...@unisa.edu.au Ph +61 8 8302 6860 Fax +61 8 8302 6870
 
 

Juan T. Llibre

unread,
Jul 10, 2001, 7:38:42 AM7/10/01
to
You have some basic VB learning to do!

Try this :
<Script Language="VB" runat="server">
Private Sub NoFrames

Response.Write("<noframes><body><p>This page uses frames, but your browser doesn't support them.</p></body></noframes>")
End Sub
</SCRIPT>
Notice...no compilation error, although nothing happens.
 
Now, add under this under that script :

<%
NoFrames
%>
 
And your Sub will execute...

For a more practical example, instead of the simple NoFrames call, use :

<%
If Request.QueryString("frames")="no" Then
NoFrames
Else
End If
%>
 
Then, if your querystring looks like this : http://server.com/FramesOrNoFrames.aspx?frames=no
 
If frames=no, the Sub will execute and render the <noframes> text;
If frames=anythingelse, or if frames is not in the querystring, the text will not be rendered.
 
To recap : if you do this :

<%
Private Sub NoFrames
Response.Write("anything")
End Sub
%>
 
You will always get the error you are getting now.
 
Procedures are compilable only if their declaration context allows it.

If you declare a Sub within a script block, it will compile.
<Script Language="VB" runat="server">
Sub ThisWillCompileOK
End Sub
</SCRIPT>
 
If you declare a Sub within <% ... %> delimiters, it will not compile.
 
<%
Sub NoWayThisWillCompile
End Sub
%>
 
best,
 
 

Juan T. Llibre
Microsoft MVP [IIS/ASP]
"Beginning ASP.NET", Wrox Press - Look for it in August!
==========================================
"David Gardiner" <david.g...@unisa.edu.au> wrote in message news:#KUIWaRCBHA.1396@tkmsftngp07...

David Gardiner

unread,
Jul 10, 2001, 8:02:08 PM7/10/01
to
 
"Juan T. Llibre" <j.ll...@codetel.net.do> wrote in message news:u7jpgUTCBHA.1436@tkmsftngp02...
You have some basic VB learning to do!
 
thanks, but i already understood that VB stuff! I think you might have been mislead by my code sample. My problem is that the subroutine is a method of a Class. I have no problem calling a subroutine in other cases!
 
Here's another example:
 
<%@ language="vb" %>
<SCRIPT LANGUAGE="vbscript" RUNAT=Server>
 

Class Fred 
 '
 ' Display message for browsers that don't support frames
 Private Sub NoFrames
 
  Response.Write("<noframes><body><p>This page uses frames, but your browser doesn't support them.</p></body></noframes>")
 
 End Sub
 
End Class
 
</SCRIPT>
 
Compilation dies on the Response.Write still.
 
any ideas now?
 
-dave
0 new messages