.NET Framework Bookmark and Share   
 index > Managed Extensibility Framework > How to pass an Enum to a Functon
 

How to pass an Enum to a Functon

I have several Enums defined and I would like to know if anyone knows how to pass an Enum to a function.

Enum

eOne

eName

eAddress

eCity

End Enum

Enum eTwo

eDate

eEmailAddress

End Enum

''' <summary>

''' Routine that passes enum,

''' </summary>

''' <param name="EnumGoesHere"></param>

''' <remarks></remarks>

Public Sub PassEnum(ByVal EnumGoesHere)

Dim sqlString As String = Nothing

sqlString =

Me.LoadHdrEnum()

End Sub

''' <summary>

''' Routine that accepts enum.

''' </summary>

''' <param name="mode"></param>

''' <param name="sqlString"></param>

''' <param name="EnumGoesHere"></param>

''' <returns></returns>

''' <remarks></remarks>

Public Shared Function LoadHdrEnum(ByVal mode As String, ByVal sqlString As String, ByVal EnumGoesHere) As String

Dim i As Int16 = 0

Dim holdString As String = Nothing

' Replace the Enum names with the numbers.

For Each enumType In [Enum].GetValues(GetType(EnumGoesHere))

Dim strMsgType As String = enumType.ToString()

sqlString = Replace(sqlString,

"hdr." & strMsgType, i)

i += 1

Next

Return sqlString

End Function

KevinHBeltway

Pls. see:

Public Enum eOne

eOne

eName

eAddress

eCity


End Enum

Enum eTwo

eDate

eEmailAddress


End Enum

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PassEnum()
End Sub

Public Sub PassEnum()


Dim enumGoesHere1 As eOne = eOne.eAddress

Dim sqlString As String = Nothing

sqlString = Me.LoadHdrEnum("", "", enumGoesHere1)


End Sub

Public Function LoadHdrEnum(ByVal mode As String, ByVal sqlString As String, ByVal EnumGoesHere As eOne) As String

Dim i As Int16 = 0


Dim holdString As String = Nothing

' Replace the Enum names with the numbers.

For Each enumType In [Enum].GetValues(GetType(eOne))


If enumType = EnumGoesHere Then
Dim ii As Int32 = 0
End If

Dim strMsgType As String = enumType.ToString()


sqlString = Replace(sqlString, "hdr." & strMsgType, i)

i += 1


Next

Return sqlString

End Function


End Class

Jiyuan

You can use google to search for other answers

Custom Search

More Threads

• wrong csv information showed up in csv file
• POCO and XML Mapping support
• How to identify, Is current user a Administrator..?
• Composite CompositionContainer or ValueResolvers?
• No "hard dependancy" but a new dependancy is introduced.
• Several contributors to unity configuration in app.config ?
• Registry access error in ApplicationBlocks.ExceptionManagement when using Custom Publisher
• What is Managed Extensibility Framework and its relationship with Enterprise Library?
• Create a Ribbon Control for MS Project
• MEF and Ninject, which are the differences between them and what does it imply?