|
-
May 5th, 2003, 10:13 PM
#1
Thread Starter
Junior Member
Enum-and this does what?
I was reading over some code i came across on one of these forums, and was wondering what enum is? or public enum "variable". could someone please explain this to me? thanks
-
May 5th, 2003, 10:47 PM
#2
Fanatic Member
Do you mean what is the definition of the term "enumeration"? That's a hard-coded list of values. A lot of the time it will be used to put human-language names to things like binary numbers, e.g. the MsgBoxStyle enumeration:
ms-help://MS.VSCC/MS.MSDNVS/vblr7/html/vamscMsgBoxConstants.htm
each of the listings in the enumeration points to a numerical value - so you have the convenience of human-readable names for values at development time, but the efficiency of a number at build time.
-
May 5th, 2003, 11:31 PM
#3
Thread Starter
Junior Member
def. & coding use
thanks for the defintion, that shed some light, but i was wondering what you would use that in code for and for what purpose. could you possibly supply an example? thanks man
-
May 6th, 2003, 12:15 AM
#4
Enums generally supply a fixed list of choices. The icons or button choices are an enum when you use the Msgbox. Here is another example:
VB Code:
Public Class EnumExample
Public Enum LoadByOptions
ByName
BySSN
ByID
End Enum
Public Sub Load(ByVal LoadBy As LoadByOptions)
Select Case LoadBy
Case LoadByOptions.ByName
Case LoadByOptions.BySSN
Case LoadByOptions.ByID
End Select
End Sub
End Class
The use of enums here makes it much easier than using a numbered list (i.e. 1, 2, 3) and easier to read since instead of numbers you have what they represent (ByName, SSN, or ID).
-
May 6th, 2003, 09:13 AM
#5
I wonder how many charact
I'm glad someone asked this, because today I have just thought about implementing one...
Here's the drill:
Customer payments.... how did they pay? Visa, Check, Cash, Discover, MasterCard, American Express?
Sounds like a great application of the enum class....
VB Code:
Private pType As PayMentType
Public Enum PayMentType
Visa = 0
Mastercard = 1
Discover = 2
AmericanExpress = 3
Cash = 4
Check = 5
End Enum
Public Property Method(ByVal aPaymntType As PayMentType) As PayMentType
Get
Return pType
End Get
Set(ByVal Value As PayMentType)
pType = Value
End Set
End Property
VB Code:
Dim r As New Payment()
r.Method = Payment.PayMentType.AmericanExpress
Of course I'm still debating whether I should even hardcode payment types in.... if a new type of credit card comes out in 2 years.. I might get some calls...
-
May 6th, 2003, 09:34 AM
#6
Fanatic Member
from my experience you should hard code as little as possible so I wouldn't if i was you! It'll only create more work for you at a later date!
-
May 6th, 2003, 11:55 AM
#7
I wonder how many charact
yea... but since this is a custom project... and the numskels wouldn't be able to figure out how to update a database, I think I'm going to have to hardcode it...
Hard-coded or not, if these change, I'll have to make a trip back... and adding a new enumeration type and a new button that represents that type would take all of 1 minute.
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
|