optikon
asked on
Objects and UDT arrays
I have created a User Defined Type called Satus, I then created two arrays WStatus and BStatus. I would like to refer to one of the two arrays with an object CStatus. Is this possible with Visual Basic 6?
Sample Code
Dim Wstatus(17) As Status
Dim Bstatus(17) As Status
Dim CStatus As Object
Private Sub Form_Load()
Blah...
Blah...
Blah...
Set CStatus = Bstatus ' this is where I get the error "object required"
End Sub
I have also tried Set CStatus = Bstatus(), and when I tried CStatus = Bstatus that gave me "Compile Error: Only User-defined tupes defined in public object modules can be coerced to or from a variant or passed to late-bound functions"
Any help would be appriciated.
Sample Code
Dim Wstatus(17) As Status
Dim Bstatus(17) As Status
Dim CStatus As Object
Private Sub Form_Load()
Blah...
Blah...
Blah...
Set CStatus = Bstatus ' this is where I get the error "object required"
End Sub
I have also tried Set CStatus = Bstatus(), and when I tried CStatus = Bstatus that gave me "Compile Error: Only User-defined tupes defined in public object modules can be coerced to or from a variant or passed to late-bound functions"
Any help would be appriciated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, I had considered a 2d array, but I never thought of using one of the diminsions as a flag, thanks.
Here is an example UDT:
Type SampleUDT
MyField1 As String
MyField2 As Long ' etc.
End Type
Add a class module like this:
----------MyClass.CLS
Option Explicit
Public MyField1 As String
Public MyField2 As Long
Now if you want an array of objects you can either use a variant array and place an object in each element.
Or use a collection.
Dim MyCollection As New Collection
Dim MyStat As MyClass
Set MyStat = New MyClass
MyStat.MyField1 = "....."
MyStat.MyField2 = 1234
MyCollection.Add MyStat