Passing Enumerator as Parameter - (ByVal myEnum AS ????)

G

Gene Berger

(See <--????? below in Sub Load_Enum for problem).

I have looked and looked ... everyone speaks about
how to use enumerators (thanks) but WHAT TYPE is
it when passing as a parameter?

p_enm As System.Enum doesn't work.
p_enm As Object doesn't work.
p_enm As Type doesn't work.

Don't laugh please - I have tried stuff like:
Dim enm As System.Enum = CType(p_enm, System.Enum)


So what does work? (See <--????? below).

Public Enum enm_cboTest1 As Integer
Completed = 1
Not_Started = 2
End Enum

Public Enum cboTest2 As Integer
Completed = 1
Not_Started = 2
End Enum

Call Load_Enum(enm_cboTest1)
Call Load_Enum(cboTest2 As Integer)


Private Sub Load_Enum(ByVal p_enm As System.Enum) <--?????
Dim names As String() = System.Enum.GetNames(GetType(p_enm))
For i As Integer = 0 To names.Length - 1
Dim myText As String = names(i).Trim.Replace("_", " ")
Dim myValue As p_enm = System.Enum.Parse(GetType(p_enm), names(i))
Dim b1 As Integer = 0
Next
End Sub
 
M

Martin H.

Hello Gene,

Private Sub Load_Enum(ByVal p_enm As enm_cboTest1)
....
End Sub

Call Load_Enum(ByVal value As enm_cboTest1)


Best regards,

Martin
 
S

Stephany Young

The type you need to pass is System.Type.

Private Sub Load_Enum(ByVal type As Type)

Dim names As String() = [Enum].GetNames(type)

For i As Integer = 0 To names.Length - 1
Dim myText As String = names(i).Trim.Replace("_", " ")
Dim myValue As Object = [Enum].Parse(type, names(i))
Dim b1 As Integer = 0
Next

End Sub

Call Load_Enum(GetType(enm_cboTest1))

Call Load_Enum(GetType(cboTest2))

Note that myValue needs to be declared as System.Object.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top