User-defined types not allowed as Public Members of object modules


I have a VB6.0 form that I use to graph data.  It maintains an array in its form module that looks like this:

    Public Type TraceInfoType
       
        iDevice As Integer
        iParameter As Integer
        iPlotSubsetIndex As Integer
        iColorIndex As Integer
        dLastTimeTenthsSec As Long
        lSubsetPointer As Long
        SubsetWrapped As Boolean
   
    End Type
   
    Dim iNumTraces As Integer
    Dim Traces(MAXTRACES) As TraceInfoType

Which obviously helps to manage data for my plot control.  I have another form that I use for troubleshooting/debugging -- I have an INI setting that invokes it on startup, and it shows a lot of the underlying data in the application so that I can actually get a good idea of the problem outside of the development environment.  I thought this was a pretty nifty idea (if I do say so myself)...

Except its capability is severely hampered by the fact that it does not have access to arrays like the Traces array above.  If I make the Traces array public, it doesn't compile because I get the error in the subject line.  If I leave it private, I can't get to it from other forms.  (What I wanted to do was have my debug form extract data periodically from this underlying array in the Chart form and put it in a listbox  on its form --just so I can see what's going on)

So the only solutions I see are to:

1) add some public functions to my chart form to extract and return the array data.  This stinks, because I'd have to write a lot of code to extract various data structures from various places, which would probably take longer than the effort the debug form would save me.

2) I could move the traces array to a global module and make it public, but this doesn't make any sense because... it belongs in the chart form! It is information that is not useful except to the chart form and should stay there.

Is there any other way to get that data out of my Traces array and into my Debug form??  I saw there is a 'friend' parameter, but couldn't make it work for me...
riceman0Asked:
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.

Harisha M GEngineerCommented:
Hi riceman0,
   
    You should change that to Private Type or place that in a seperate code module. (Insert --> Module)

Bye
---
Harish
Harisha M GEngineerCommented:
riceman0,
    You cannot use Friend for Type
riceman0Author Commented:

Actually, nice catch: it is a private type, the above won't compile, cut-and-paste error.  I had it public briefly in a separate code module.

But that's aside from the point of my question, I am more interested in the Array than the type.  (The type I could live with  being in a separate module, but the array has no business being global.)

Also, I was playing with Friend on the function that accesses it, not the type itself.

This limitation angers me because

(a) this is possible in C, so why not VB?  What's so much more difficult about allowing this in VB?
(b) my user type is just seven primitive types in a row, nothing crazy?  I could get the effect I want by delcaring it in seven different, primitive arrays:

public iDevice(MAXTRACES) as integer
Public iParameter(MAXTRACES) as Integer
(and so on)

This is the SAME effect!  Should have the same footprint in memory.  I just change the location of my subscripts.  But it looks really stupid!  Why, why, why can't I just make that array public (or function as public with some keyword).  My gut tell me there has to be a way because there should be a way.
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

Harisha M GEngineerCommented:
(a) this is possible in C, so why not VB?  What's so much more difficult about allowing this in VB?

Not in C, That should be C++

In VB also, you can declare Classes as Friend, but not Types.
riceman0Author Commented:

Okay.  I'll leave this open for a while, see if anyone has been frustrated by this, has a clever workaround.
BurbbleCommented:
It seems silly to stress yourself out over this (which I think cannot be done this way) when you can just put it in a module and declare it as Public. To keep it organized, make a "modChart" to compliment "frmChart", or whatever naming convention you use.

Honestly it seems like a lot of trouble over nothing :/

Maybe I misunderstood though...
amebaCommented:
It is possible to have User-defined type as Public Member in the form (if UDT is defined in public object module).
What is not possible is having public array, e.g. this won't compile (except in bas module):
   Public iParameter(0 to 5) as Integer

Why?  I guess public members are implemented using COM rules and VB arrays cannot follow them.

Workaround:  "1) add some public functions to my chart form"
is possible (in ActiveX project), but friend is easier:

Friend Property Get Trace(Index As Long) As TraceInfoType
    Trace = Traces(Index)
End Property

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
riceman0Author Commented:

Thank you that is a lot easier, using friend, than I had in mind.

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
Fonts Typography

From novice to tech pro — start learning today.