Home |
Search |
Today's Posts |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
In a quick glance I can't see anything obvious wrong, all the objects looks
as if they clear down in an orderly way. Not sure if same applies to your real life set up if say object ref's to class's are at global level. You could change a few things along the following lines and see if it makes any difference. 'Public Function setdata(ss As String) ' data_ = ss 'End Function ' 'Public Function getdata() As String ' getdata = data_ ' why the underscore's 'End Function Public Property Let propData(ss As String) 'data_ = ss data = ss End Property Public Property Get propData() As String propData = data ' data_ End Property use like this newMySmallObject.propData = ss ss = newMySmallObject.propData similarly with functions setname & getname Public Function printout() ' Dim ss As mySmallObjectClass Dim i As Long 'Integer i = 0 ' For Each ss In mySmallObjectList For i = 1 To mySmallObjectList.Count 'i = i + 1 'Debug.Print ("Item " & i & " in " & name & ": " & ss.getdata()) ' Debug.Print ("Item " & i & " in " & name & ": " & mySmallObjectList(i).getdata()) Debug.Print "Item " & i & " in " & name & ": " & mySmallObjectList(i).propData Next End Function Regards, Peter T wrote in message ps.com... Peter T wrote: Hi Eric, There's a lot that doesn't make sense. I started trying to second guess the objectives but gave up, can't see how it ever worked at all yet alone make Excel crash. You have typed code direct into the post rather than copying the original, I suspect typos and/or omissions occurred while doing that. Regards, Peter T Hi Peter, Sorry for typing code directly (sincerely - I myself hate when people do that. It's always wrong). This is a scaled-down, tested version which I copied and pasted. The idea is that I have objects with data which I have in my own container class. This is the data-class: ----------- mySmallObjectClass ------------- Private data_ As String Public Function setdata(ss As String) data_ = ss End Function Public Function getdata() As String getdata = data_ End Function --------------------------------------------------- This is the container-class ---------- myContainerClass ----------------- Dim mySmallObjectList As Collection Dim name As String Private Sub Class_Initialize() Set mySmallObjectList = New Collection End Sub Private Sub Class_Terminate() Set mySmallObjectList = Nothing End Sub Public Function setname(ss As String) name = ss End Function Public Function getname() As String getname = name End Function Public Function add(ss As String) Dim newMySmallObject As New mySmallObjectClass newMySmallObject.setdata (ss) mySmallObjectList.add newMySmallObject, ss End Function Public Function printout() Dim ss As mySmallObjectClass Dim i As Integer i = 0 For Each ss In mySmallObjectList i = i + 1 Debug.Print ("Item " & i & " in " & name & ": " & ss.getdata()) Next End Function Public Function subcontainer(s As String) As myContainerClass Set subcontainer = New myContainerClass Dim ss As mySmallObjectClass For Each ss In mySmallObjectList If ss.getdata < s Then subcontainer.add (ss.getdata) Next End Function Public Function item(key As String, val As String) mySmallObjectList.item(key).setdata (val) End Function -------------------------------------------------------------------------- ---- And finally a sub for doing tests: ------------------- MODULE 1 ----------------- Public Sub runtests() 'Fill my container Dim myContainerObject As myContainerClass Set myContainerObject = New myContainerClass myContainerObject.setname ("OrigContainer") myContainerObject.add ("apple") myContainerObject.add ("banana") myContainerObject.add ("citrus") myContainerObject.add ("dates") myContainerObject.add ("esparagus") myContainerObject.add ("figs") myContainerObject.add ("gherkins") myContainerObject.add ("hallonberries") 'Print out the members in the container myContainerObject.printout 'Create a sub-container Dim subContainerObject As myContainerClass Set subContainerObject = myContainerObject.subcontainer("d") subContainerObject.setname ("SubContainer") subContainerObject.printout 'Now change an object in original container and look if it's changes in subcontainer myContainerObject.item "apple", "pear" 'set object data to "pear" instead of apple myContainerObject.printout subContainerObject.printout End Sub -------------------------------------------------- So to my problems: It works as expected, but I am a bit worried since my Excel crashes every time I shut it down. I would be very happy if someone could say if my setup with the container class function "subcontainer" returning a reference is a good idea or not. I am quite new to VB, but not to OO-programming, so I would like all help, tips and pointers! //Eric |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
function to find value and return cell reference | Excel Discussion (Misc queries) | |||
how do I create a cell reference from ADDRESS function return? | Excel Worksheet Functions | |||
return the column reference number of a function result | Excel Discussion (Misc queries) | |||
Function return by reference | Excel Programming | |||
Function unable to return Collection object | Excel Programming |