473,385 Members | 2,014 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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

Thanks for any help




Nov 21 '05 #1
8 1508
"Peter Stojkovic" <Pe*************@gmx.net> wrote in message news:uA**************@TK2MSFTNGP14.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.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)
Nov 21 '05 #2
"Peter Stojkovic" <Pe*************@gmx.net> schrieb:
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)
///

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

Nov 21 '05 #3
Peter Stojkovic schrieb:
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
Nov 21 '05 #4
CT
Peter,

Try this:

xx = CType(textbox1.text, enum1)
--
Carsten Thomsen
Enterprise Development with VS .NET, UML, AND MSF
http://www.apress.com/book/bookDisplay.html?bID=105
Communities - http://community.integratedsolutions.dk

"Peter Stojkovic" <Pe*************@gmx.net> wrote in message
news:uA**************@TK2MSFTNGP14.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.text)

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

Thanks for any help



Nov 21 '05 #5
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

"Peter Stojkovic" <Pe*************@gmx.net> wrote in message
news:uA**************@TK2MSFTNGP14.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.text)
|
| But Cint is not possible. How can I assign the user-input ( for example
99 )
| to varibale xx ??
|
|
|
| Thanks for any help
|
|
|
|
|
|
|
|
|
|
Nov 21 '05 #6
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?

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:u3**************@TK2MSFTNGP10.phx.gbl...
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

"Peter Stojkovic" <Pe*************@gmx.net> wrote in message
news:uA**************@TK2MSFTNGP14.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.text)
|
| But Cint is not possible. How can I assign the user-input ( for example
99 )
| to varibale xx ??
|
|
|
| Thanks for any help
|
|
|
|
|
|
|
|
|
|

Nov 21 '05 #7
> 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
Nov 21 '05 #8
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eD**************@TK2MSFTNGP12.phx.gbl...
"Peter Stojkovic" <Pe*************@gmx.net> schrieb:
Dim xx as enum1
xx = cint(textbox1.text)

\\\
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.
Nov 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Nikhil Patel | last post by:
Hi all, I am a VB6 programmer and learning C#. I am currently reading a chapter on types. I have question regarding enums. Why do we need to convert enum members to the value that they represent?...
21
by: Andreas Huber | last post by:
Hi there Spending half an hour searching through the archive I haven't found a rationale for the following behavior. using System; // note the missing Flags attribute enum Color {
1
by: Anonieko Ramos | last post by:
Answer: http://weblogs.asp.net/tims/archive/2004/04/02/106310.aspx by Tim Sneath I've come across the situation on a number of occasions when coding where I've wanted to convert from a string...
7
by: The Last Gunslinger | last post by:
We have an enum: public enum EnumDays { Sun = 1, Mon = 2, ... } We can store it as a byte:
3
by: Shimon Sim | last post by:
I am writing general method that would take Type that should represent a enum that do something with it. In the middle of the method I need to cast it to this enum. I tried Convert.ChangeType...
2
by: Dennis | last post by:
I have an enum as follows: Public Enum myData FirstData = 6 SecondData = 7 end enum Is there anyway that I can return the Enum names by their value, i.e., I want to input 6 into a function...
8
by: kc | last post by:
I'm trying to pull data from a database that I have no control over the structure of. There's a members table with a column for the member's sex. It just stores the sex as M or F. I'd like to...
5
by: Barry | last post by:
Hello, In VS2003, I tried using an enum and setting it into a field in a datarow. It seems as if the datatype of the field in the row determined what went into the field. If the datatype was...
8
by: tony | last post by:
Hello! I have below a for loop and a switch in the for loop. I have also a enum called colBlowStep with some values. I have also an array called m_columnBlowStep with some strings. All items in...
3
by: shapper | last post by:
Hello, I have an enum: Public Enum Color Red Blue Green End Enum
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.