|
-
Jan 13th, 2004, 01:12 AM
#1
Convert and Enum to integer?
say I have this:
Enum Alpha
A
B
C
End Enum
Is there a way to do this same thing without using Cint:
Dim val As Ineger = CInt(Alpha.A)
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Jan 13th, 2004, 03:14 AM
#2
Sleep mode
Originally posted by MrPolite
say I have this:
Enum Alpha
A
B
C
End Enum
Is there a way to do this same thing without using Cint:
Dim val As Ineger = CInt(Alpha.A)
It returns integer as default datatype . So you don't have to convert it .
VB Code:
Dim val As Ineger = Alpha.A
-
Jan 13th, 2004, 08:37 AM
#3
Heres an example of an enum.
VB Code:
Friend Enum enumDatabaseType As Byte
DBAccess97 = 1
DBAccess2000 = 2
DBSQLServer = 3
End Enum
When you use it, its not a number, or an integer, its an enum type. If you do "MyVal.ToString" it will result in "DBAccess2000" for example, but if you want the number, it will convert it for you (as the format you specify like above).
Last edited by Grimfort; Jan 13th, 2004 at 08:40 AM.
-
Jan 13th, 2004, 08:44 AM
#4
Sleep mode
Originally posted by Grimfort
When you use it, its not a number, or an integer, its an enum type. If you do "MyVal.ToString" it will result in "DBAccess2000" for example, but if you want the number, it will convert it for you (as above).
NO
Enum are basically integral values . If you didn't provide the values for each one , they start counting from zero . Remember Enums can't be string values but can be converted to string as you just did .
-
Jan 13th, 2004, 10:41 AM
#5
May I suggest you read this:
http://support.microsoft.com/default...n-us;311327#1e
Main part being:
Enumerators are value types that have their own set of methods.
You can also use them alongside reflection to use things like ModuleBuilder.DefineEnum, and EnumBuilder.DefineLiteral (Ive not used them personally tho).
Edit: Notice the edit in the post b4, I wanted to make it more clear.
-
Jan 13th, 2004, 10:50 AM
#6
Sleep mode
Originally posted by Grimfort
May I suggest you read this:
http://support.microsoft.com/default...n-us;311327#1e
Main part being:
Enumerators are value types that have their own set of methods.
You can also use them alongside reflection to use things like ModuleBuilder.DefineEnum, and EnumBuilder.DefineLiteral (Ive not used them personally tho).
Edit: Notice the edit in the post b4, I wanted to make it more clear.
I can't see any relation to the problem presented here . The point is : No explicity conversion is needed since the default type of declared enum is integer .
-
Jan 13th, 2004, 10:53 AM
#7
I agree. What were you saying no to then ? I just said that an enum is of type enum, that automatically converts to the declared format.
-
Jan 13th, 2004, 11:18 AM
#8
Sleep mode
Originally posted by Grimfort
When you use it, its not a number, or an integer, its an enum type. If you do "MyVal.ToString" it will result in "DBAccess2000" for example, but if you want the number, it will convert it for you (as the format you specify like above).
I said no because conversion isn't necessary her (as you did).
-
Jan 13th, 2004, 11:39 AM
#9
Thats why I edited my post, it wasnt clear enough. I thought you were saying no, that an enum was not a type, but "basically integral values". I didnt mean to sound shirty.
-
Jan 13th, 2004, 04:03 PM
#10
-
Jan 13th, 2004, 05:34 PM
#11
It was a technical discussion . Nothing like a little heat to warm the forums.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|