Results 1 to 6 of 6

Thread: Public User Defined Types

  1. #1

    Thread Starter
    Fanatic Member TheVader's Avatar
    Join Date
    Oct 2002
    Location
    Rotterdam, the Netherlands
    Posts
    871

    Question Public User Defined Types

    I'm trying to use a public User Defined Type from within a class module. The UDT has been declared in a public module, the instance in a class module, like this:
    VB Code:
    1. 'Module:
    2. Public Type tText
    3.     Font As String
    4.     Format As String
    5. End Type
    6.  
    7. 'Class Module
    8. Public Text as tText
    This is not allowed, apparently. The compiler gives me this error:
    Quote Originally Posted by VB Compiler
    Constants, fixed-length strings, arrays, user-defined types and Declare statements not allowed as Public members of object modules.
    Why can't UDT's be used publicly?
    Author for Visual Basic Web Magazine

    My articles on the Web Browser Control:
    Using the Web Browser Control & Using the DHTML Document Object Model

    The examples referenced in the articles can be found here:

  2. #2

  3. #3
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359

    Re: Public User Defined Types

    There's no point in using a UDT from within a Class Module. A Class Module will provide you with all of the capabilities of a UDT with additional OO functionality.
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  4. #4
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: Public User Defined Types

    one slight thing...

    Public Text as tText

    Reserved word.. won't work because of that

    try

    Public sText As tText
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  5. #5

    Thread Starter
    Fanatic Member TheVader's Avatar
    Join Date
    Oct 2002
    Location
    Rotterdam, the Netherlands
    Posts
    871

    Re: Public User Defined Types

    Thanks for your replies. I've been using lots of class modules in my application and therefore I was trying UDT's; in this case I'd have to add five new class modules holding only a few variables each. It clutters up my structure...

    @dannymking: good catch, hadn't noticed that.
    Author for Visual Basic Web Magazine

    My articles on the Web Browser Control:
    Using the Web Browser Control & Using the DHTML Document Object Model

    The examples referenced in the articles can be found here:

  6. #6
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Public User Defined Types

    Quote Originally Posted by dannymking
    one slight thing...
    Public Text as tText
    Reserved word.. won't work because of that
    Text is not a reserved word.

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