[RESOLVED] Return Description from Enum List
Hi all
I have a user-defined class question. In my class I use an enumerated list for product type. I can read and write this value to an instance of the class.
What I need to do now is read the string value for the instance from the enumerated list.
Here's what I have so far.
The ProdDesc property should, for example, retun a value of "Desktop" when privProdType = 1.
I'm hoping I can do this without using a SELECT CASE syntax. (The Product list is much longer in real life.
VB Code:
Dim privProdType As Product
Public Enum Product
Desktop = 1
Notebook = 2
Server = 3
Printer = 4
'etc, etc
End Enum
Public Property Let ProdType(newType As Product)
privProdType = newType
End Property
Public Property Get ProdType() As Product
ProdType = privProdType
End Property
Public Property Get ProdDesc() As String
'some code to get the desc from the Enum list - based on privProdType
End Property
Re: Return Description from Enum List
AFAIK, a Select Case is the best option :(
The good news is that MZTools (link in my sig) can create all the Cases for you.
Re: Return Description from Enum List
If you use a Dictionary, you can:
Function Keys()
Member of Scripting.Dictionary
Get an array containing all keys in the dictionary.
You can also:
Function Items()
Member of Scripting.Dictionary
Get an array containing all items in the dictionary.
I find Dictionaries very useful. You draw your own conclusions.
Re: Return Description from Enum List
Dictioary looks like the way to go.
Thanks Webtest