Archived

This topic is now archived and is closed to further replies.

VB6 Collection Problem

This topic is 5009 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, i was working around with collection and had a hard time findin what is my problem I have a Class clsPiece, in this class i have a Collection of clsSegments When I do : Dim Piece As New clsPiece Dim myNewSegment as new clsSegment Piece.Segments.Add myNewSegment <-- here''s the problem it doesnt want only the new Segment, it wants parameters for evrything that a segment is... i would like to be able to pass just an object of type clsSegment and not the parameters of a new clsSegment the Segment structure is shown below Private mcolVectors As Vectors Private mcolLitVertexes As LitVertexes Private mcolOriginVectors As OriginVectors Private mcolCells As Cells So a segment is an object that has 4 collections in it... is there a way to just initialise all the thing to 0 like vb does so well... i saw in the msdn help exemples something like that: Piece.Segments.Add Item:=myNewSegment first time I see the ":=" operator in VB6 and i tried their exemple and still doesnt work

Share this post


Link to post
Share on other sites
o..k

Next time, it would be more helpful if you simply copy and paste code rather than trying to describe it.

Dim Piece As New clsPiece
Dim myNewSegment as new clsSegment

Maybe:

Dim Piece As New clsPiece
Dim myNewSegment as new Collection
myNewSegment.add Piece

??

[edited by - Manip on March 25, 2004 2:15:51 PM]

Share this post


Link to post
Share on other sites
Damm my problem waas that i used index 0 instead of 1 for the first element, boy i feel like a noob

ok, maybe another noob question, what''s the best way to save an object in a binary file...I tried:

Open App.Path & myRec!AssociatedFile For Binary As #1
Put #1, 1, CurrentPiece
Close 1

VB gives me an error that says Object variable cannot be PUT in a file, i looked at the help file and they said you must save each property of the object manualy... this would be possible for me but a painful job... anyone has a suggestion?

Share this post


Link to post
Share on other sites
Well, you can't dump a function or sub can you?! If you want to be able to write it to a file, use user-defined types aka a struct.

User-Defined type ~ Rap Class ~ Dump class property aka user defined type

Type Thing
value1 string
value2 string
value3 int
end type

ClassX:
Public Thing as MyType

Public Property Get store() As Variant
store = thing.valuex
End Property

Public Property Let store(ByVal vNewValue As Variant)
thing.valuex = vnewvalue
End Property

End ClassX

Open App.Path & myRec!AssociatedFile For Binary As #1
Put #1, , CurrentPiece.Thing
Close 1


[edited by - Manip on March 25, 2004 7:32:52 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by md_lasalle
I did some user defined types first, and it was workin well with the PUT but because i have dynamic arrays i''m stuck with using classes


Your what? Why? wa?

Share this post


Link to post
Share on other sites