ENUM how to convert

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Stojkovic

    #1

    ENUM how to convert

    I have an ENUM

    Public Enum enum1 As Integer
    STEP_00= 0
    STEP_01= 1
    STEP_02=2
    .....
    STEP_999=999
    end enum

    When the user makes an input like 99

    the variable xx should be set.

    Dim xx as enum1
    xx = cint(textbox1.t ext)

    But Cint is not possible. How can I assign the user-input ( for example 99 )
    to varibale xx ??



    Thanks for any help










  • Al Reid

    #2
    Re: ENUM how to convert

    "Peter Stojkovic" <Peter.Stojkovi c@gmx.net> wrote in message news:uAlnqKWgFH A.1468@TK2MSFTN GP14.phx.gbl...[color=blue]
    > I have an ENUM
    >
    > Public Enum enum1 As Integer
    > STEP_00= 0
    > STEP_01= 1
    > STEP_02=2
    > ....
    > STEP_999=999
    > end enum
    >
    > When the user makes an input like 99
    >
    > the variable xx should be set.
    >
    > Dim xx as enum1
    > xx = cint(textbox1.t ext)
    >
    > But Cint is not possible. How can I assign the user-input ( for example 99 )
    > to varibale xx ??
    >
    >
    >
    > Thanks for any help
    >
    >[/color]

    Dim xx As enum1

    xx = CType(textbox1. text, enum1)


    Comment

    • Herfried K. Wagner [MVP]

      #3
      Re: ENUM how to convert

      "Peter Stojkovic" <Peter.Stojkovi c@gmx.net> schrieb:[color=blue]
      >I have an ENUM
      >
      > Public Enum enum1 As Integer
      > STEP_00= 0
      > STEP_01= 1
      > STEP_02=2
      > ....
      > STEP_999=999
      > end enum
      >
      > When the user makes an input like 99
      >
      > the variable xx should be set.
      >
      > Dim xx as enum1
      > xx = cint(textbox1.t ext)
      >
      > But Cint is not possible. How can I assign the user-input ( for example
      > 99 ) to varibale xx ??[/color]

      \\\
      xx = CType(CInt(Me.T extBox1.Text), Enum1)
      ///

      --
      M S Herfried K. Wagner
      M V P <URL:http://dotnet.mvps.org/>
      V B <URL:http://classicvb.org/petition/>

      Comment

      • Armin Zingler

        #4
        Re: ENUM how to convert

        Peter Stojkovic schrieb:[color=blue]
        > I have an ENUM
        >
        > Public Enum enum1 As Integer
        > STEP_00= 0
        > STEP_01= 1
        > STEP_02=2
        > .....
        > STEP_999=999
        > end enum
        >
        > When the user makes an input like 99
        >
        > the variable xx should be set.
        >
        > Dim xx as enum1
        > xx = cint(textbox1.t ext)
        >
        > But Cint is not possible. How can I assign the user-input ( for example 99 )
        > to varibale xx ??[/color]

        xx = ctype(textbox1. text, enum1)


        Armin

        Comment

        • CT

          #5
          Re: ENUM how to convert

          Peter,

          Try this:

          xx = CType(textbox1. text, enum1)


          --
          Carsten Thomsen
          Enterprise Development with VS .NET, UML, AND MSF

          Communities - http://community.integratedsolutions.dk

          "Peter Stojkovic" <Peter.Stojkovi c@gmx.net> wrote in message
          news:uAlnqKWgFH A.1468@TK2MSFTN GP14.phx.gbl...[color=blue]
          >I have an ENUM
          >
          > Public Enum enum1 As Integer
          > STEP_00= 0
          > STEP_01= 1
          > STEP_02=2
          > ....
          > STEP_999=999
          > end enum
          >
          > When the user makes an input like 99
          >
          > the variable xx should be set.
          >
          > Dim xx as enum1
          > xx = cint(textbox1.t ext)
          >
          > But Cint is not possible. How can I assign the user-input ( for example
          > 99 ) to varibale xx ??
          >
          >
          >
          > Thanks for any help
          >
          >
          >
          >
          >
          >
          >
          >
          >
          >[/color]


          Comment

          • Jay B. Harlow [MVP - Outlook]

            #6
            Re: ENUM how to convert

            Peter,
            In addition to the other comments, you can use Enum.IsDefined to ensure that
            the Textbox's value is a value Enum1 value.

            Something like:

            If Not [Enum].IsDefined(GetT ype(enum1), textbox1.text) Then
            Throw New ArgumentOutOfRa ngeException("T extBox1.Text",
            textbox1.text, "Invalid enum1 value")
            End If

            Hope this helps
            Jay

            "Peter Stojkovic" <Peter.Stojkovi c@gmx.net> wrote in message
            news:uAlnqKWgFH A.1468@TK2MSFTN GP14.phx.gbl...
            |I have an ENUM
            |
            | Public Enum enum1 As Integer
            | STEP_00= 0
            | STEP_01= 1
            | STEP_02=2
            | ....
            | STEP_999=999
            | end enum
            |
            | When the user makes an input like 99
            |
            | the variable xx should be set.
            |
            | Dim xx as enum1
            | xx = cint(textbox1.t ext)
            |
            | But Cint is not possible. How can I assign the user-input ( for example
            99 )
            | to varibale xx ??
            |
            |
            |
            | Thanks for any help
            |
            |
            |
            |
            |
            |
            |
            |
            |
            |


            Comment

            • Robin Tucker

              #7
              Re: ENUM how to convert

              Hmmmm, which reminds me - a while back someone posted a website where you
              could get a complete list of all exception classes that can be thrown by
              components (eg. ArgumentOutOfRa ngeException), along with a details of where
              you should use them. Can anyone reccie this and post a link?

              "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP @msn.com> wrote in message
              news:u3JBfsWgFH A.4032@TK2MSFTN GP10.phx.gbl...[color=blue]
              > Peter,
              > In addition to the other comments, you can use Enum.IsDefined to ensure
              > that
              > the Textbox's value is a value Enum1 value.
              >
              > Something like:
              >
              > If Not [Enum].IsDefined(GetT ype(enum1), textbox1.text) Then
              > Throw New ArgumentOutOfRa ngeException("T extBox1.Text",
              > textbox1.text, "Invalid enum1 value")
              > End If
              >
              > Hope this helps
              > Jay
              >
              > "Peter Stojkovic" <Peter.Stojkovi c@gmx.net> wrote in message
              > news:uAlnqKWgFH A.1468@TK2MSFTN GP14.phx.gbl...
              > |I have an ENUM
              > |
              > | Public Enum enum1 As Integer
              > | STEP_00= 0
              > | STEP_01= 1
              > | STEP_02=2
              > | ....
              > | STEP_999=999
              > | end enum
              > |
              > | When the user makes an input like 99
              > |
              > | the variable xx should be set.
              > |
              > | Dim xx as enum1
              > | xx = cint(textbox1.t ext)
              > |
              > | But Cint is not possible. How can I assign the user-input ( for example
              > 99 )
              > | to varibale xx ??
              > |
              > |
              > |
              > | Thanks for any help
              > |
              > |
              > |
              > |
              > |
              > |
              > |
              > |
              > |
              > |
              >
              >[/color]


              Comment

              • Alex Clark

                #8
                Re: ENUM how to convert

                > Hmmmm, which reminds me - a while back someone posted a website where you[color=blue]
                > could get a complete list of all exception classes that can be thrown by
                > components (eg. ArgumentOutOfRa ngeException), along with a details of
                > where you should use them. Can anyone reccie this and post a link?[/color]

                Sorry to hijack but I'd be really interested in this if someone does find
                it...

                Thanks,
                Alex Clark


                Comment

                • Phill.  W

                  #9
                  Re: ENUM how to convert

                  "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
                  news:eDxLeOWgFH A.3616@TK2MSFTN GP12.phx.gbl...[color=blue]
                  > "Peter Stojkovic" <Peter.Stojkovi c@gmx.net> schrieb:[color=green]
                  > > Dim xx as enum1
                  > > xx = cint(textbox1.t ext)
                  > >[/color]
                  > \\\
                  > xx = CType(CInt(Me.T extBox1.Text), Enum1)
                  > ///[/color]

                  Looks almost to good to be true. The stock code /I've/ been using
                  for doing this is more like

                  xx = DirectCast( _
                  [Enum].Parse( GetType(enum1), Me.TextBox1.Tex t ) _
                  , enum1 )

                  (Other than simplicity), Is there any advantage of one over the other?

                  Regards,
                  Phill W.


                  Comment

                  Working...