Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

User-Defined Type - pls help

Status
Not open for further replies.

kensheehimura1

Programmer
Jun 2, 2003
19
PH
good day everybody, i have a problem in a class, i have a user defined type called RECT which got in the API viewer, i declared it inside the class, and declared it also as a parameter to the one procecure, but i recieve the error, the error is "Only Public user defined types defined in public object module or as a fields of public user defined types "

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type


Public Sub Draw(ByVal Width, ByVal Height As Long, ByVal SrcHdc As Long, ByVal PicBox As Object, ByVal Text As String, ByVal Textlength As Long, ByVal State As Long, byval r as RECT )

'code goes here

End Sub


how can i pass the user defined type as an argument, or how can i use it as a return value for a property like this

Public Property Get Lpdis() As DRAWITEMSTRUCT
Lpdis = mLpdis
End Property

tnx,

 
You'd think it would work wouldn't you. But sorry it doesn't. I could go into why the marshelling in vb doesn't support it but we don't really have to go that deep.

But what you can do is define a Rect Class in your Library. It can then accept parameters of that type and return them too.

So its basically the same but instead of just declaring it you'll have to instanciate it also.

Code will look almost the same.
 
tnx, but how can i do that, can u pls give me an example of code, a simple one, im just a beginner to VB, pls, tnx again,
 
is the problem "Private Type"? I use "Type" in a ".bas" module which I just copied from the MSDN help files. In such a module it is available to all forms etc.
 
>is the problem "Private Type"? I use "Type" in a ".bas" module which I just copied from the MSDN help files. In such a module it is available to all forms etc.

Yep thats the problem, the code outside the class can't see the definition of RECT, so putting it in the module declared public is a solution. Semperfidownunda has suggested an alternative solution, which I think, is better in OOP terms.

Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top