|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Referencing User Defined Type from another moduleI 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
Show quote
Hide quote
"Chris Lieb" <ChrisL***@discussions.microsoft.com> wrote in message But the UDT isn't defined in a public object module; BAS code modules aren'tnews: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. 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..."
Show quote
Hide quote
"Chris Lieb" <ChrisL***@discussions.microsoft.com> wrote in message A form's not a public object module. UDTs are a pain imo. Someone that uses 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 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.. 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 procfilled in a public BAS proc -- Show quoteHide quoteRandy Birch MS MVP Visual Basic http://vbnet.mvps.org/ ---------------------------------------------------------------------------- Read. Decide. Sign the petition to Microsoft. http://classicvb.org/petition/ ---------------------------------------------------------------------------- "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 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 "Chris Lieb" <ChrisL***@discussions.microsoft.com> wrote in message Un-classlike? I don't get it. The suggestion I made was to *replace* the 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 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.. 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.. > > > "Chris Lieb" <ChrisL***@discussions.microsoft.com> wrote Just wait until you have to use; Set xxx = New <class> every time you> 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. 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 "Larry Serflaten" <serfla***@usinternet.com> wrote in message Using Set is now too much trouble? Sheesh. I'd rather type those 3 letters 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 > 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.. "Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote If you want to discuss VB.Net, try:> 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# microsoft.public.dotnet.general microsoft.public.dotnet.languages.vb :-P The OP said he didn't feel like he was using objects. I pointed out onedifference he'll need to keep in mind, over the UDT's he had been using. Who mentioned anything about .Net??? LFS
VB.NET Discussion
Object navigation with <Enter> key stroke Squeezing too much into a control... Combobox, ITEMData and Reselected previous item Use ActiveX DLL in VB.net Rounding Negative Number Toward Zero Dr. Watson "Access violoation" error How to identify and extract bounced email info? Auto Finding in ComboBox List Wheel mouse and VB |
|||||||||||||||||||||||