Results 1 to 22 of 22

Thread: How does it work? Why does it work this way?

Hybrid View

  1. #1
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: How does it work? Why does it work this way?

    Is there any setting (e.g.
    Code:
    Option Even Stricter
    ) that prevents passing an integer through a parameter that expects an enum?

    Or - what do you recommend instead?

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: How does it work? Why does it work this way?

    Quote Originally Posted by Merrion
    Is there any setting (e.g.
    Code:
    Option Even Stricter
    ) that prevents passing an integer through a parameter that expects an enum?

    Or - what do you recommend instead?
    But arent enums just fancy names for integers?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3
    Frenzied Member Phill64's Avatar
    Join Date
    Jul 2005
    Location
    Queensland, Australia
    Posts
    1,201

    Re: How does it work? Why does it work this way?

    Quote Originally Posted by Atheist
    But arent enums just fancy names for integers?
    Yes, Integers, Longs or Bytes can be an enum.
    The enum name itself is just an alias to a value of any of those types.

    Being able to put a direct value in makes sense.
    And why wouldn't you want to do so? especially in circumstances when you're reading settings or the like.

  4. #4
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: How does it work? Why does it work this way?

    No - enums should allow for a greater deal of type safety than integers.

    If you have an enum
    Code:
    Public Enum VehicleDrivenWheels
        TwoWheelDrive = 2
        FourWheelDrive = 4
    End Enum
    you should not be able to say:
    Code:
    Dim MyCarDrivenWheels As VehicleDrivenWheels = 739
    It is this way because when you combine enums (that are set as <flags()> ) together and this would technically allow any integer - but I'd like some way of saying : treat this enum as not combineable...even as a specific attribute you have to set to make it so...

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