Click to See Complete Forum and Search --> : User-defined data types and Classes


deepak_warrier
October 5th, 1999, 02:43 PM
I want to create a user-defined data-type that can be used by my classes.
I put the code



public Type Part
PartID as string
Qty as Byte
End Type





in my standard module(.bas file).

But I get the error message
"Only public user-defined types defined in object modules can be used as parameters or return types for public procedures of class modules or as fields for public user defined types" during the compilation of




public Function Add(p as Part)

Dim i as Integer

'jkjkjskdj
'ksdkjkjsdkj
'iwusjdus



End Function





which is in my class module.
Help says the help topic is not anchored and that it cannot be found.

If I put the user-defined data type definition in the Class module, VB says that is not possible too.

What's the way out?

Deepak

Ps. Please try to reply with complete code of an example application ;-)

czimmerman
October 5th, 1999, 04:43 PM
For this to work, you have to put both the function and the UDT in the .bas module.

However, here is another suggestion to consider: why not make the UDT a class? That way, you can use it as a parameter and pass it around any which way you want.

Bruno
October 5th, 1999, 05:39 PM
For this to work, your project should be ActiveX project (not Standard exe)
Put your UDT declaration in class module, with Instancing=6 'GlobalMultiUse

suntosh
October 6th, 1999, 02:00 AM
this kind of user-defined types can be in an ActiveX exe (instead of the Standard Exe)

I tried this. Check it out !!

On Form1 (with just Command1) :
Private Sub Command1_Click
Dim p As Person
p.Name = "suntosh"
p.Age = 55
c.Add p
End Sub

In Module1 :
Public c As New Class1

Public Sub main()
Form1.Show
End Sub


In Class1:
Public Type Person
Name As String
Age As Integer
End Type

Public Function Add(p As Person)
MsgBox p.Name
MsgBox p.Age
End Function