Enum
Could Anyone change the following vb.net codes to VB6??
Please.
Private Enum ImportantsEnumeration
Low = 0
Normal = 1
High = 2
End Enum
''Looping Enums ...
For Each i As Integer In [Enum].GetValues(GetType(ImportantsEnumeration))
MsgBox(i)
Next
''Adding Enum to Combox Box. ...
cboImportants.Items.AddRange(System.Enum.GetNames(GetType(ImportantsEnumeration)))
[553 byte] By [
Sync] at [2007-11-11 6:20:22]

# 1 Re: Enum
As far as I know, VB6 provides no way to return the string representation of an enum value; I believe that the string representation is removed during the compile process. You may work around this limitation by creating a module ("Importance") that contains both the enum and a public read-only property that returns the string representation of each enum value:
Option Explicit
Public Enum eImportance
Low
Normal
High
End Enum
Public Property Get Name(ByVal Value As eImportance)
Dim sName As String
Select Case Value
Case 0
sName = "Low"
Case 1
sName = "Normal"
Case 2
sName = "High"
Case Else
End Select
Name = sName
End Property
You could then convert your VB.NET code to this:
With cboImportance
.AddItem Importance.Name(eImportance.Low)
.AddItem Importance.Name(eImportance.Normal)
.AddItem Importance.Name(eImportance.High)
End With
# 4 Re: Enum
VB6 Enum objects does not support... enumeration. Only Collections and arrays do. I usually define an Enum and a Collection, using the enumeration as key. in your case
dim importance as Collection
set importance = new Collection
importance.Add "Low", Str(eImportance.Low)
importance.Add "Normal", Sct(Importance.Normal)
importance.Add "High", Sct(Importance.High)
...
The drawback is that any change in the enumeration type causes a change in the collection.
Marco
mstraf at 2007-11-11 17:31:40 >
