?
Solved

Objects and UDT arrays

Posted on 2003-02-27
3
Medium Priority
?
200 Views
Last Modified: 2010-04-07
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.
0
Comment
Question by:optikon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 17

Expert Comment

by:inthedark
ID: 8037723
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
 
LVL 4

Accepted Solution

by:
AdsB earned 400 total points
ID: 8037929
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
 

Author Comment

by:optikon
ID: 8044452
Thanks, I had considered a 2d array, but I never thought of using one of the diminsions as a flag, thanks.
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month9 days, 17 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question