Visual Basic Classic
--
Questions
--
Followers
Top Experts
I have, (slightly simplified example) the following: one module mdlStartup and one form frmMain.
mdlStartup contains a public UDT like this:
Public Type DIAGRAM
title AS String
End Type
There are more fields but this will suffice for the example.
frmMain works fine with its own Private DS as DIAGRAM instance, but I now want to move all of frmMain's functions into modules and keep only form-specific code in frmMain.
So, to make sure I'd be able to, I made the following test routines in frmMain:
Public Sub test1()
Dim dsTest As DIAGRAM
dsTest.title = "TestABC"
test2 dsTest
End Sub
Public Sub test2(dsInput As DIAGRAM)
MsgBox dsInput.title
End Sub
Then in mdlStartup I called frmMain.test1() straight after frmMain.show.
Going into debug mode, I expected "TestABC" to pop up, but the program didn't even run. Instead:
"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"
The UDT is defined public and my modules are, as far as I know, public and everything in them can be called from frmMain without trouble so it seems public to me.. so what is this talking about, and how can I fix it please?
This capability of using my UDT as a parameter, either ByVal or ByRef (preferably ByRef, but having no luck with either) is vital if I'm to move all my functions out of frmMain and into a module. (Hopefully I will then be able to use the module in other projects which require the same functionality, providing portability and not relying on frmMain being present.. eventually want to mould this into an ActiveX control without just copy/pasting everything into two versions)
Thanks for any light you can shed on this..
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon98/html/vbconfriendpropertiesmethods.asp
Rajesh
Nice catch.. :P
Just changing the scope to Friend fixes it all, even though I cannot totally understand the logic behind it yet.
Thankyou.






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Visual Basic Classic
--
Questions
--
Followers
Top Experts
Visual Basic is Microsoft’s event-driven programming language and integrated development environment (IDE) for its Component Object Model (COM) programming model. It is relatively easy to learn and use because of its graphical development features and BASIC heritage. It has been replaced with VB.NET, and is very similar to VBA (Visual Basic for Applications), the programming language for the Microsoft Office product line.