ENUM how to convert

  • Thread starter Thread starter Peter Stojkovic
  • Start date Start date
P

Peter Stojkovic

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.text)

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



Thanks for any help
 
Peter Stojkovic said:
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.text)

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



Thanks for any help

Dim xx As enum1

xx = CType(textbox1.text, enum1)
 
Peter said:
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.text)

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

xx = ctype(textbox1.text, enum1)


Armin
 
Peter Stojkovic said:
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.text)

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

\\\
xx = CType(CInt(Me.TextBox1.Text), Enum1)
///
 
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(GetType(enum1), textbox1.text) Then
Throw New ArgumentOutOfRangeException("TextBox1.Text",
textbox1.text, "Invalid enum1 value")
End If

Hope this helps
Jay

|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.text)
|
| But Cint is not possible. How can I assign the user-input ( for example
99 )
| to varibale xx ??
|
|
|
| Thanks for any help
|
|
|
|
|
|
|
|
|
|
 
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. ArgumentOutOfRangeException), along with a details of where
you should use them. Can anyone reccie this and post a link?
 
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. ArgumentOutOfRangeException), along with a details of
where you should use them. Can anyone reccie this and post a link?

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

Thanks,
Alex Clark
 
Herfried K. Wagner said:
\\\
xx = CType(CInt(Me.TextBox1.Text), Enum1)
///

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.Text ) _
, enum1 )

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

Regards,
Phill W.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top