Valhalla Legends Archive

Programming => General Programming => Topic started by: Barumonk on April 12, 2003, 10:11 PM

Title: [VB] ReDim Preserve with a Class Module
Post by: Barumonk on April 12, 2003, 10:11 PM
Would it be possible to do this?

Public CModule() As New ClassModule
ReDim CModule(0)

...then later in the program...

ReDim Preserve CModule(UBound(CModule) + 1)

I was going to create a winsock using api in a class module and use this as a way to add a new socket without knowing how many would be needed beforehand, but I thought it would be best to ask first incase I might be wasting my time.
Title: Re:[VB] ReDim Preserve with a Class Module
Post by: Yoni on April 13, 2003, 12:11 AM
You can't do that.

If you want your Winsock class module to use events, it has to be declared WithEvents. And then, it can't be an array, or at least not a dynamically sized one (don't remember which).
Even if it was a class module that didn't use WithEvents, I'm pretty sure it's impossible to ReDim an array of class modules.

+1 (good coding style, well asked question).
Title: Re:[VB] ReDim Preserve with a Class Module
Post by: Barumonk on April 13, 2003, 12:44 AM
Thanks, you just saved me alot of time and trouble.  I'll find another way eventually, there is always a way to do something, it just depends on how hard you reach for it if you succeed or fail.
Title: Re:[VB] ReDim Preserve with a Class Module
Post by: TheMinistered on April 13, 2003, 08:39 AM
Perhaps we can help you explore for other alternatives.  If you could post what you are trying to make, and what you want it to do etc... perhaps we can help!
Title: Re:[VB] ReDim Preserve with a Class Module
Post by: Banana fanna fo fanna on April 13, 2003, 10:16 AM
+1 to Barumonk for same reasons stated above.
Title: Re:[VB] ReDim Preserve with a Class Module
Post by: Zakath on April 13, 2003, 10:36 AM
+1 to St0rm because he needs all the help he can get.
Title: Re:[VB] ReDim Preserve with a Class Module
Post by: Banana fanna fo fanna on April 13, 2003, 10:54 AM
Damn.
Title: Re:[VB] ReDim Preserve with a Class Module
Post by: Noodlez on April 13, 2003, 03:55 PM
If using a winsock API class, what you can do is add another paramter to all the events (Optional Index as Long) Then, when raising the event give the corresponding index.

And, in the procedure for it...
Private Sub CSocket_DataArrival(bytesTotal as long, Index as long)
Dim strData as string
CSocket(Index).GetData  strdata
End Sub