From: mp on
more an observation than a question, but I welcome any discussion that
follows....

seems strange i can't define a private udt inside a private class and pass
it to private/or public proceedures inside the class itself.

compile error
Only user-defined types defined in public object modules can be coerced to
or from a variant or passed to late-bound functions

the error occurs because i tried to add a udt to a collection(thus casting
to variant)
'Private Type tDims
' DimStartPoint As Variant
' DimEndPoint As Variant
' DimTextOverride As String
'End Type
'Private Sub AddToDimsCollection(otDim As tDims)
mColDims.Add otDim

i have solved my actual problem by converting the udt to a class - so this
is more a question for information sake

initially i thought i'd try a udt since there were only 3 properties and I
thought since it was all private in the same class i wouldn't get the
private/public compile error i get whenever I try to (mis-)use a udt.

the normal fix to use a udt that i've seen so far is the udt has to be
defined public in a public bas module.
in this case the error says has to be public object module which i don't
think (?) a bas module qualifies
(and it didn't work when i tried so i think thats right)

the other fix might be to make the class instancing public/not creatable but
i don't think i want to use that, when i'm simply trying to use a simple udt
to pass a couple values
the other fix i've seen is declare the sub Friend rather than Private but
that didn't work either since the error is still trying to put the udt into
a collection

i have had almost no luck trying to use a simple udt if it has to be passed
anywhere due to all the strange(to me) limitations (really the limitations
of my knowledge)
it's just always been easier to create a class instead than try to figure
out what hoops to jump through to use a simpler(i would have thought)
construct.

thanks
mark


From: Jim Mack on
mp wrote:

Did you try 'Friend'?

--
Jim Mack
Twisted tees at http://www.cafepress.com/2050inc
"We sew confusion"



> more an observation than a question, but I welcome any discussion
> that follows....
>
> seems strange i can't define a private udt inside a private class
> and pass it to private/or public proceedures inside the class
> itself.
>
> compile error
> Only user-defined types defined in public object modules can be
> coerced to or from a variant or passed to late-bound functions
>
> the error occurs because i tried to add a udt to a collection(thus
> casting to variant)
> 'Private Type tDims
> ' DimStartPoint As Variant
> ' DimEndPoint As Variant
> ' DimTextOverride As String
> 'End Type
> 'Private Sub AddToDimsCollection(otDim As tDims)
> mColDims.Add otDim
>
> i have solved my actual problem by converting the udt to a class -
> so this is more a question for information sake
>
> initially i thought i'd try a udt since there were only 3
> properties and I thought since it was all private in the same class
> i wouldn't get the private/public compile error i get whenever I
> try to (mis-)use a udt.
>
> the normal fix to use a udt that i've seen so far is the udt has to
> be defined public in a public bas module.
> in this case the error says has to be public object module which i
> don't think (?) a bas module qualifies
> (and it didn't work when i tried so i think thats right)
>
> the other fix might be to make the class instancing public/not
> creatable but i don't think i want to use that, when i'm simply
> trying to use a simple udt to pass a couple values
> the other fix i've seen is declare the sub Friend rather than
> Private but that didn't work either since the error is still trying
> to put the udt into a collection
>
> i have had almost no luck trying to use a simple udt if it has to
> be passed anywhere due to all the strange(to me) limitations
> (really the limitations of my knowledge)
> it's just always been easier to create a class instead than try to
> figure out what hoops to jump through to use a simpler(i would have
> thought) construct.
>
> thanks
> mark
From: Kevin Provance on
Top posted (feeling lazy today):

I think I read somewhere declaring such things as Friend, versus Private or
Public solves this.

--
Customer Hatred Knows No Bounds at MSFT
Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc

Bawwk! Paulie want a dingleball, bawwk!
"mp" <nospam(a)Thanks.com> wrote in message
news:i3jv2i$c0k$1(a)news.eternal-september.org...
: more an observation than a question, but I welcome any discussion that
: follows....
:
: seems strange i can't define a private udt inside a private class and pass
: it to private/or public proceedures inside the class itself.
:
: compile error
: Only user-defined types defined in public object modules can be coerced to
: or from a variant or passed to late-bound functions
:
: the error occurs because i tried to add a udt to a collection(thus casting
: to variant)
: 'Private Type tDims
: ' DimStartPoint As Variant
: ' DimEndPoint As Variant
: ' DimTextOverride As String
: 'End Type
: 'Private Sub AddToDimsCollection(otDim As tDims)
: mColDims.Add otDim
:
: i have solved my actual problem by converting the udt to a class - so this
: is more a question for information sake
:
: initially i thought i'd try a udt since there were only 3 properties and I
: thought since it was all private in the same class i wouldn't get the
: private/public compile error i get whenever I try to (mis-)use a udt.
:
: the normal fix to use a udt that i've seen so far is the udt has to be
: defined public in a public bas module.
: in this case the error says has to be public object module which i don't
: think (?) a bas module qualifies
: (and it didn't work when i tried so i think thats right)
:
: the other fix might be to make the class instancing public/not creatable
but
: i don't think i want to use that, when i'm simply trying to use a simple
udt
: to pass a couple values
: the other fix i've seen is declare the sub Friend rather than Private but
: that didn't work either since the error is still trying to put the udt
into
: a collection
:
: i have had almost no luck trying to use a simple udt if it has to be
passed
: anywhere due to all the strange(to me) limitations (really the limitations
: of my knowledge)
: it's just always been easier to create a class instead than try to figure
: out what hoops to jump through to use a simpler(i would have thought)
: construct.
:
: thanks
: mark
:
:

From: ralph on
On Sat, 7 Aug 2010 10:45:21 -0500, "mp" <nospam(a)Thanks.com> wrote:

>more an observation than a question, but I welcome any discussion that
>follows....
>
>seems strange i can't define a private udt inside a private class and pass
>it to private/or public proceedures inside the class itself.
>
>compile error
>Only user-defined types defined in public object modules can be coerced to
>or from a variant or passed to late-bound functions
>
>the error occurs because i tried to add a udt to a collection(thus casting
>to variant)
>'Private Type tDims
>' DimStartPoint As Variant
>' DimEndPoint As Variant
>' DimTextOverride As String
>'End Type
>'Private Sub AddToDimsCollection(otDim As tDims)
> mColDims.Add otDim
>

You are sort of hammering on two separate problems.
To answer the last one first - you can not store a UDT in a VB
Collection.

One way to get around that is to write your own Collection based on an
Array. You can store UDTs in VB Arrays.

There are several examples on the web. Here is one to get you started.
http://www.mvps.org/vbvision/collections.htm

As for the first question - you need to declare/define the UDT in a
Public Module. That means using a Public Base module, or Friend, or
writing a Type Library for the UDT (the latter essentially serves as a
"Public Module".

Or you might consider combining your custom collection with an Object
in an ActiveX Dll which you could use with your project.
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q185700

Anyway, just fuel for thought.

-ralph


From: ralph on
On Sat, 07 Aug 2010 12:51:14 -0500, ralph <nt_consulting64(a)yahoo.net>
wrote:


>
>Anyway, just fuel for thought.
>

Forgot to mention the possiblitity of storing the UDT as an Array()
object (the VB Array object). You can store Array()s in a Variant, and
thus in a Collection.

Ugly, but have seen it done. <g>

-ralph
 |  Next  |  Last
Pages: 1 2 3
Prev: Temp File -- got me stumped
Next: Cleanup remnants