Results 1 to 2 of 2

Thread: Req Help: Extending UDTs and specifying their values

  1. #1
    Guest

    Talking

    Okay, I like UDTs - they are not seemingly popular or recommended yet to a self-proclaimed geek, quite fun.

    If I were to create a UDT as:

    Code:
    Private Type MyUDTs
        iMyInt as Integer
        bytMyByte as Byte
        sMyStr(1 to 3) as String
    End Type
    
    Private MyUDT as MyUDTs
    How would I implement VB's code hinting/autocomplete such as a boolean presenting a popup with True/False as the values?

    Code:
    MyUDT.iMyInt =
    After the "=", the VB popup offers values I have previously set.

    Also can UDTs be embedded within UDTs?

    • * MyUDT(ThisUDT).iMyInt
      * MyUDT(ThatUDT).iMyInt


    To anyone who might know ... THANKS!

  2. #2
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357
    Well, if you want the autocomplete (intellisense) feature to prompt you with True/False for the values, set the datatype to a Boolean!

    i.e:
    Code:
    Private Type MyUDTs
        bMyBool As Boolean
        bytMyByte As Byte
        sMyStr(1 To 3) As String
    End Type
    
    Private MyUDT As MyUDTs
    Now when you type
    Code:
    MyUDT.bMyBool =
    it will give you True/False as possiblities.

    As for the second part of your question, the short answer is yes, you can have udts inside other udts. There is a restriction in that you must predefine a udt to use it in another one. The long (and correct) answer is: Try it and see!!!

    Example (notice that the last Type, Employee, contains other user-defined types):
    Code:
    Option Explicit
    
    Private Enum enmMaritalStatus
        msSingle
        msMarried
        msDivorced
        msWidowed
    End Enum
    
    Private Type udtName
        Title As String
        First As String
        Middle As String
        Last As String
    End Type
    
    Private Type udtAddress
        Street As String
        Street2 As String
        City As String
        State As String
        Zip As Integer
    End Type
    
    Private Type Employee
        EmpName As udtName
        Address As udtAddress
        MaritalStatus As enmMaritalStatus
    End Type
    If you like the autocomplete feature, then you will love this. Try this example:
    Code:
    Dim Fred As Employee ' right away, Employee shows up in the list of data-types to choose from
    Fred.Address.City = "New York" ' after each "." you get a list of choices
    Fred.MaritalStatus = msMarried ' after the "=" you get a list of marital status choices
    Also, in regards to your first statement, Types are used fairly regularly in some areas, but often you will find that anything you define a type for can be encapsulated in a class. Classes are more popular from an object-oriented programming point of view.

    Hope that helps!
    ~seaweed

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