Home All Groups Group Topic Archive Search About

Referencing User Defined Type from another module

Author
9 May 2005 10:05 PM
Chris Lieb
I have a UDT, addField, in a module, modBase, that is declared with Public
scope.  I am using it as a return type of a Public function in a form,
frmSLIC_report.  When I try to compile the program, I get the error:

Compile error:
Only public user defined types defined in public object modules can be used
as parameters or return types for public procedures of class modules or as
fields of public user defined types.

I feel like I meet all of these criteria, having a Public UDT and using it
as the return type of a Public function.  What's up?  I really need to get
some progress on this app and it's hard to show progress when it no longer
compiles!

Thanks in advance,
Chris

Author
9 May 2005 10:11 PM
Bob Butler
Show quote Hide quote
"Chris Lieb" <ChrisL***@discussions.microsoft.com> wrote in message
news:07DDB04B-3055-4F04-8E0A-8E3BC4FF5B07@microsoft.com
> I have a UDT, addField, in a module, modBase, that is declared with
> Public scope.  I am using it as a return type of a Public function in
> a form, frmSLIC_report.  When I try to compile the program, I get the
> error:
>
> Compile error:
> Only public user defined types defined in public object modules can
> be used as parameters or return types for public procedures of class
> modules or as fields of public user defined types.
>
> I feel like I meet all of these criteria, having a Public UDT and
> using it as the return type of a Public function.

But the UDT isn't defined in a public object module; BAS code modules aren't
public or objects.

Show quoteHide quote
> What's up?  I
> really need to get some progress on this app and it's hard to show
> progress when it no longer compiles!
>
> Thanks in advance,
> Chris

--
Reply to the group so all can participate
VB.Net: "Fool me once..."
Author
9 May 2005 10:12 PM
Ken Halter
Show quote Hide quote
"Chris Lieb" <ChrisL***@discussions.microsoft.com> wrote in message
news:07DDB04B-3055-4F04-8E0A-8E3BC4FF5B07@microsoft.com...
>I have a UDT, addField, in a module, modBase, that is declared with Public
> scope.  I am using it as a return type of a Public function in a form,
> frmSLIC_report.  When I try to compile the program, I get the error:
>
> Compile error:
> Only public user defined types defined in public object modules can be
> used
> as parameters or return types for public procedures of class modules or as
> fields of public user defined types.
>
> I feel like I meet all of these criteria, having a Public UDT and using it
> as the return type of a Public function.  What's up?  I really need to get
> some progress on this app and it's hard to show progress when it no longer
> compiles!
>
> Thanks in advance,
> Chris

A form's not a public object module. UDTs are a pain imo. Someone that uses
UDTs once in a while may pop in with a "cure" but, imo, the fastest, easiest
and best way to fix it is to get rid of the UDT and use a class module
instead..

Converting a User Defined Type to a Class Module
http://www.vbsight.com/UDT_Class.htm

--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
Sign up now to help keep VB support alive - http://classicvb.org/petition
Please keep all discussions in the groups..
Author
10 May 2005 1:37 AM
Randy Birch
The error is not referring to the module-level UTD declaration of addField,
but rather that the scope of the procedure that returns an addField UDT,
when defined within a form, must be a private procedure.  It's the Public
scope for the procedure that's causing the problems. Basically it's saying
you can not define a UDT as public within in a module then try to have a
private entity such as a form return a the defined UTD.  You can pass a
variable declared as the UDT to the private procedure, and then that
procedure can be declared Public.  Or, you can return the UDT from a Public
procedure located in the same or another BAS module.

'BAS MOD
Option Explicit

Public Type addField
   field1 As String
   field2 As String
End Type


'ANOTHER (OR THE SAME) BAS MOD
Public Function aPublicBasProcedure() As addField

   aPublicBasProcedure.field1 = "filled in a"
   aPublicBasProcedure.field2 = "public BAS proc"

End Function


'SOME FORM
Option Explicit

Private Sub Command1_Click()

   Dim a As addField
   a = aPrivateProcedure()
   Debug.Print a.field1, a.field2

End Sub

Private Sub Command2_Click()

   Dim a As addField
   Call aPublicProcedure(a)
   Debug.Print a.field1, a.field2

End Sub

Private Sub Command3_Click()

   Dim a As addField
   a = aPublicBasProcedure()
   Debug.Print a.field1, a.field2

End Sub


Private Function aPrivateProcedure() As addField

   aPrivateProcedure.field1 = "filled in a"
   aPrivateProcedure.field2 = "private proc"

End Function

Private Function aPublicProcedure(af As addField) As Boolean

   af.field1 = "filled in a"
   af.field2 = "public proc"

End Function

> filled in a   private proc
   filled in a   public proc
   filled in a   public BAS proc

--

Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/
----------------------------------------------------------------------------
Read. Decide. Sign the petition to Microsoft.
http://classicvb.org/petition/
----------------------------------------------------------------------------



Show quoteHide quote
"Chris Lieb" <ChrisL***@discussions.microsoft.com> wrote in message
news:07DDB04B-3055-4F04-8E0A-8E3BC4FF5B07@microsoft.com...
:I have a UDT, addField, in a module, modBase, that is declared with Public
: scope.  I am using it as a return type of a Public function in a form,
: frmSLIC_report.  When I try to compile the program, I get the error:
:
: Compile error:
: Only public user defined types defined in public object modules can be
used
: as parameters or return types for public procedures of class modules or as
: fields of public user defined types.
:
: I feel like I meet all of these criteria, having a Public UDT and using it
: as the return type of a Public function.  What's up?  I really need to get
: some progress on this app and it's hard to show progress when it no longer
: compiles!
:
: Thanks in advance,
: Chris
Author
10 May 2005 2:11 PM
Chris Lieb
Thanks everyone.  I ended up putting all of my UDTs in class modules to
prevent any more of these errors from popping up.  I'm just so used to using
OOP languages like C# that the seemingly un-classlike structure of VB6 kind
of threw me for a loop.

Chris

Show quoteHide quote
"Chris Lieb" wrote:

> I have a UDT, addField, in a module, modBase, that is declared with Public
> scope.  I am using it as a return type of a Public function in a form,
> frmSLIC_report.  When I try to compile the program, I get the error:
>
> Compile error:
> Only public user defined types defined in public object modules can be used
> as parameters or return types for public procedures of class modules or as
> fields of public user defined types.
>
> I feel like I meet all of these criteria, having a Public UDT and using it
> as the return type of a Public function.  What's up?  I really need to get
> some progress on this app and it's hard to show progress when it no longer
> compiles!
>
> Thanks in advance,
> Chris
Author
10 May 2005 2:18 PM
Ken Halter
"Chris Lieb" <ChrisL***@discussions.microsoft.com> wrote in message
news:C3755D33-904B-4E6B-8B9A-531BF78B45DE@microsoft.com...
> Thanks everyone.  I ended up putting all of my UDTs in class modules to
> prevent any more of these errors from popping up.  I'm just so used to
> using
> OOP languages like C# that the seemingly un-classlike structure of VB6
> kind
> of threw me for a loop.
>
> Chris

Un-classlike? I don't get it. The suggestion I made was to *replace* the
UDTs *with* classes... not move them *to* classes. Guaranteed not
un-classlike.

What ever works I guess.

--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
Sign up now to help keep VB support alive - http://classicvb.org/petition
Please keep all discussions in the groups..
Author
10 May 2005 3:09 PM
Chris Lieb
I didn't move the UDTs to Class Modules, I just moved the variables to Class
Modules so I could use them like UDTs.  As for the un-classlike comment I mad
before, I just meant that there is no explicit statement in the code like:

class Add: noFunctionality {
    ....
}

to make me feel like I am actually programming a class, that's all.

Chris

Show quoteHide quote
"Ken Halter" wrote:

> "Chris Lieb" <ChrisL***@discussions.microsoft.com> wrote in message
> news:C3755D33-904B-4E6B-8B9A-531BF78B45DE@microsoft.com...
> > Thanks everyone.  I ended up putting all of my UDTs in class modules to
> > prevent any more of these errors from popping up.  I'm just so used to
> > using
> > OOP languages like C# that the seemingly un-classlike structure of VB6
> > kind
> > of threw me for a loop.
> >
> > Chris
>
> Un-classlike? I don't get it. The suggestion I made was to *replace* the
> UDTs *with* classes... not move them *to* classes. Guaranteed not
> un-classlike.
>
> What ever works I guess.
>
> --
> Ken Halter - MS-MVP-VB - http://www.vbsight.com
> Sign up now to help keep VB support alive - http://classicvb.org/petition
> Please keep all discussions in the groups..
>
>
>
Author
10 May 2005 3:26 PM
Larry Serflaten
"Chris Lieb" <ChrisL***@discussions.microsoft.com> wrote

> I didn't move the UDTs to Class Modules, I just moved the variables to Class
> Modules so I could use them like UDTs.  As for the un-classlike comment I mad
> before, I just meant that there is no explicit statement in the code like:
>
> class Add: noFunctionality {
>     ....
> }
>
> to make me feel like I am actually programming a class, that's all.


Just wait until you have to use;  Set xxx = New <class>  every time you
want to create a new object full of variables.  Of course for frequent re-use,
you might want to institute a dynamic pool of such objects....  <g>

LFS
Author
10 May 2005 3:31 PM
Ken Halter
"Larry Serflaten" <serfla***@usinternet.com> wrote in message
news:exKfKQXVFHA.2700@TK2MSFTNGP12.phx.gbl...
>
>
> Just wait until you have to use;  Set xxx = New <class>  every time you
> want to create a new object full of variables.  Of course for frequent
> re-use,
> you might want to institute a dynamic pool of such objects....  <g>
>
> LFS
>

Using Set is now too much trouble? Sheesh. I'd rather type those 3 letters
everytime than have to put up with the reams of extra typing you have to do
in B#

--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
Sign up now to help keep VB support alive - http://classicvb.org/petition
Please keep all discussions in the groups..
Author
10 May 2005 4:06 PM
Larry Serflaten
"Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote

> Using Set is now too much trouble? Sheesh. I'd rather type those 3 letters
> everytime than have to put up with the reams of extra typing you have to do
> in B#


If you want to discuss VB.Net, try:

microsoft.public.dotnet.genera­l
microsoft.public.dotnet.langua­ges.vb

:-P

The OP said he didn't feel like he was using objects.  I pointed out one
difference he'll need to keep in mind, over the UDT's he had been using.

Who mentioned anything about .Net???

LFS