Results 1 to 3 of 3

Thread: structure/enum question

  1. #1

    Thread Starter
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    structure/enum question

    I've got a program installed here which has a form which people can fill out. One of it's drop down boxes allows you to select a value from either "default", "none" or you can enter a value from 0 to 100 in it (for a percentage).

    I want to expose ths field from a class I'm writing, so when a class instance is created, this value can be set & a method called to fill this entry in the form.

    What is the best / most professional way of exposing something like this which can allow multiple data types? I don't really want to expose this as a string if I can help it to minimize the chance of a wrong figure being specified.

    VB Code:
    1. Public Structure xyz
    2.     Public _default as boolean
    3.     Public none     as Boolean
    4.     Public Percentage as system.web.ui.webcontrols.unit
    5. End Structure
    6.  
    7. Public Enum xyz
    8.     _default     = 0
    9.     none         = 1
    10.     _1percent    = 2
    11.     _2percent    = 3
    12.     ...
    13.     _100percent  = 102
    14. End Class
    These are about the only ways I can think of, neither of which look any good! Can anyone recommend how I could do this please?

    Thanks!

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    How about just specifying it as an Integer, and use 1 or 2 special values?

    e.g.
    -2 = None
    -1 = Default
    0 = 0%
    1 = 1%
    2 = 2%
    etc.

    That would be the quickest from a performance point of view anyway..., it would also make it easier to expand upon if you developed a more complicated version of your application - i.e. Integers are serializable whereas Enums are not
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  3. #3

    Thread Starter
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Not a bad suggestion there! Cheers Jamie, I owe you a pint for that!

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

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