CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 1999
    Location
    Trivandrum, Kerala, INDIA.
    Posts
    32

    User-defined data types and Classes

    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 ;-)



  2. #2

    Re: User-defined data types and Classes

    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.


  3. #3
    Join Date
    Sep 1999
    Posts
    202

    Re: User-defined data types and Classes

    For this to work, your project should be ActiveX project (not Standard exe)
    Put your UDT declaration in class module, with Instancing=6 'GlobalMultiUse


  4. #4
    Join Date
    Oct 1999
    Location
    India
    Posts
    5

    Re: User-defined data types and Classes

    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



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured