none
Variable Enum?

    Question

  • I am using VB 2010.

    I am creating a custom control textbox. One of the features is a decimal numeric textbox with precision. Here is the precision enum below:

        Public Enum enum_Precision
            None = 0
            One_Decimal = 1
            Two_Decimal = 2
            Three_Decimal = 3
        End Enum

    When I should this to management, they said, they want a variable option. They want the ability to type a number into the properties of the control in the Visual Studio IDE. So if they type 3 then it is 3 decimal precision.

    Can I create a variable property on the IDE that my custom control read in? If so, how?

    Thursday, May 30, 2013 2:34 PM

Answers

  • Enum is intended for cases where you know in advance what the possible values are.  If you are supposed to allow for any number of decimal places, you should probably just have an integer to store the number of places.
    Thursday, May 30, 2013 2:46 PM
  • If your custom control exposes the property DecimalPlaces as an integer, then the property value can be set as any integer value, and the property box will accept an integer as input.  Your Property Get can then validate that input against your enum values, and convert and save it as an enum for the the purposes of the control.  You need to decide what to do with input that is a valid integer, but is either too small (any negative number) or too large for your range of enums.  You could either reject the input or default to a minimum and maximum repectively.

    Thursday, May 30, 2013 10:59 PM

All replies

  • Enum is intended for cases where you know in advance what the possible values are.  If you are supposed to allow for any number of decimal places, you should probably just have an integer to store the number of places.
    Thursday, May 30, 2013 2:46 PM
  • If your custom control exposes the property DecimalPlaces as an integer, then the property value can be set as any integer value, and the property box will accept an integer as input.  Your Property Get can then validate that input against your enum values, and convert and save it as an enum for the the purposes of the control.  You need to decide what to do with input that is a valid integer, but is either too small (any negative number) or too large for your range of enums.  You could either reject the input or default to a minimum and maximum repectively.

    Thursday, May 30, 2013 10:59 PM