Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Class within a Class

Status
Not open for further replies.

jgos

Programmer
Sep 27, 2002
38
0
0
US
Can you have a class within a class in an ASP page. I get a syntax error when I try to define a new class inside of a class.
 
Apparently not.

This gives me an error.
Code:
<%
Class X 
	Public msgX
	
	Public Sub init ()
		msgX = &quot;Initialized Class X&quot;
	End Sub
        
	Class Y
	   Public msgY
	End Class

End Class
%>

But this works.
Code:
<%
Class X 
	Public msgX
	Public itsaYthing
	
	Public Sub init ()
		msgX = &quot;Initialized Class X&quot;
		Set itsaYthing = new Y
		itsaYthing.init
	End Sub
End Class


Class Y
	Public msgY
	
	Public Sub init ()
		msgY = &quot;Initialized Class Y&quot;
	End Sub

End Class



Dim rptX
Set rptX = new X
rptX.init
%>

<html>
<head>
	<title>No Class</title>
</head>

<body>

Report from Class X: <%= rptX.msgX %>
<br>
Report from Class Y:  <%= rptX.itsaYthing.msgY %> 

</body>
</html>

So a class can be used within another class but it must be defined outside of the class.
 
Exactly. Class definitions cannot go inside other classes, except with certain languages that do thing like allow you to create referenced classes that will only be instantiated at the same time as they are defined.

Think about it in terms of language. If I were to define the word &quot;Dictionary&quot;
Dictionary: a reference book containing an alphabetical list of words with information about them
But then inside that defintion further define the word &quot;reference&quot;
Reference Inside Dictionary: a book about the relation between a word or phrase and the object or idea it refers to containing an alphabetical list of words with information about them
E say we also define book
Reference, Book Inside Dictionary: a physical object consisting of a number of pages bound together about the relation between a word or phrase and the object or idea it refers to containing an alphabetical list of words with information about them


It's the same thing with Classes. The definition of a class belongs outside of the instantiation of the class. If you were to define the definition of a private class inside a larger class, it would only be evaluated when you were actually creating an object of that larger class. It would be the same as saying the work book is only defined like it is above when it is used in reference to a dictionary, and only when talking about a physical dictionary, rather then the defintion or idea of one.

GHopefully that wasn't to twisted...sorry, little sleep, lots of work, not enough coffee in the world :)

-Tarwn

[sub]01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111[/sub]
minilogo.gif alt=tiernok.com
The never-completed website
 
I ended up breaking everything out of classes and making everything public. Thanks for your help though!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top