Valhalla Legends Forums Archive | General Programming | [VB] ReDim Preserve with a Class Module

AuthorMessageTime
Barumonk
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.
April 13, 2003, 3:11 AM
Yoni
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).
April 13, 2003, 5:11 AM
Barumonk
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.
April 13, 2003, 5:44 AM
TheMinistered
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!
April 13, 2003, 1:39 PM
St0rm.iD
+1 to Barumonk for same reasons stated above.
April 13, 2003, 3:16 PM
Zakath
+1 to St0rm because he needs all the help he can get.
April 13, 2003, 3:36 PM
St0rm.iD
Damn.
April 13, 2003, 3:54 PM
Noodlez
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
April 13, 2003, 8:55 PM

Search