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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

assign to object within object

Status
Not open for further replies.

compdrmt

Programmer
Sep 22, 2002
60
0
0
US
I have searched in the forums and not found this

I have a class, one of its variables is another collection class

I can successfully create the first object and within its init event I create the other collection.

for example

class tstudent
collection class tstudents

class tclassroom
collection class tclassrooms

When I create an object of type classroom I also create an object within it of type students this works ok.

that is when I write

dim classrooms as tclassrooms
set classrooms= new tclassrooms

classrooms.add vars

' within tclassroom is this code

Private Sub Class_Initialize()

Set mvarStudents = New tstudents

End Sub

everything Zen to this point the debugger says an object of type tstudents is all ready to go within each classroom object

however when I try to create a student within students

such as
classrooms(1).students.add(var, var2, varetc )

I get error 438 object doesn't support this property or method.

Any ideas on why this error.




Debugging is the process of removing bugs. Programming is the process of putting them in
 
tstudents and its properties and methods don't automatically become visible outside of the new object you created them in.

You would have to expose its objects and methods by creating new properties and methods as part of the new object.
 
thank you rdroske

Actually I am creating the only property needed (for this example) in the init function

Private Sub Class_Initialize()

Set mvarStudents = New tstudents

End Sub


I actually figured this one out.


I was (for some reason I am still not sure) not getting a correct reference to the newly created object

in the example classroom

so to get around this I used the following construct

dim newclassrrom as tclassroom

set newclassroom = classrooms.add ....

(which I probably should have been using all along)

then I can use the newclassroom object to access the vars a and methods in the newly created object classrooms(n)

so newclassroom.students.add var , var2

works just fine




Debugging is the process of removing bugs. Programming is the process of putting them in
 
I would still like to know however why I can not refer to an item in the collection by the key value sent in to the add method



Debugging is the process of removing bugs. Programming is the process of putting them in
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top