Results 1 to 7 of 7

Thread: Resolved: Data Type

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 1999
    Posts
    49

    Resolved: Data Type

    Not sure if this can be done, but I would think that you could. Basically what I'm wanting to know is if you are creating a new object, is there a way to create a new data type for one of the properties? I'll try to give a simple example. If I wanted one property to be "Gender" is there a way to create a data type that allows only the "Female" and "Male" options for that property, like "True" and "False" with other properties? Hopefully that makes sense.

    Thanks in advance!
    Last edited by Cmathis; Sep 24th, 2003 at 09:57 AM.

  2. #2
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    i really didnt get it
    you want to create a class/struct that has an enum saying Woman, Man?
    \m/\m/

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 1999
    Posts
    49
    In a simple fashion, yes. I was just giving that as an example. I want to be able to do something like this:

    Human.Gender = "Male"
    or
    Human.Gender = "Female"

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Use an Enum:
    VB Code:
    1. Public Class Human
    2.     Public Enum Genders
    3.         Male
    4.         Female
    5.     End Enum
    6.  
    7.     Private _Gender As Genders
    8.  
    9.     Public Property Gender() As Genders
    10.         Get
    11.             Return _Gender
    12.         End Get
    13.         Set(ByVal Value As Genders)
    14.             _Gender = Value
    15.         End Set
    16.     End Property
    17. End Class
    18.  
    19. 'syntax
    20. Dim you As New Human
    21. you.Gender=Male

  5. #5

    Thread Starter
    Member
    Join Date
    Jan 1999
    Posts
    49
    That works fine, but now I have one more question. If you have a string now that is "Male", can that be casted to the Genders type instead of being a string?

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Yes.
    VB Code:
    1. Dim you As New Human
    2. you.Gender=[Enum].Parse(gettype(Genders),"Male")

  7. #7

    Thread Starter
    Member
    Join Date
    Jan 1999
    Posts
    49
    Thank you VERY much!

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