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.
optikonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

inthedarkCommented:
Instead of using a UDT you could create a class module.

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

0
AdsBCommented:
Here is a very easy suggestion for you:-

instead of these lines:


Dim Wstatus(17) As Status
Dim Bstatus(17) As Status
Dim CStatus As Object


Just substitute these:

Dim BothStatuses(1,17) As Status
Dim CStatus As Integer

You can now read your status as follows

   BothStatuses(CStatus, N)

When CStatus is "0" you will get one set of values, when it is "1" you will get the other set.

This is called a two-dimensional array.


I hope this helps


AdsB
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
optikonAuthor Commented:
Thanks, I had considered a 2d array, but I never thought of using one of the diminsions as a flag, thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.