How pass an enum as parameter to a function
-
I want to pass an Enum to a function like this: Private Enum AnyEnum a b End Enum Public Sub Any(ByVal Enumeration As [Enum]) ... ... End Sub .. .. Call Any(AnyEnum) .. How can this be done? Regards Hardy
-
I want to pass an Enum to a function like this: Private Enum AnyEnum a b End Enum Public Sub Any(ByVal Enumeration As [Enum]) ... ... End Sub .. .. Call Any(AnyEnum) .. How can this be done? Regards Hardy
Firstly, you aren't able to expose a private member as a parameter of a public method. Here's some working code:
Module Module1
Public Enum AnyEnum
a
b
End EnumPublic Sub Any(ByVal Enumeration As AnyEnum) End Sub Sub Main() Any(AnyEnum.a) End Sub
End Module
Does this help you? Cheers, Simon "The day I swan around in expensive suits is the day I hope someone puts a bullet in my head.", Chris Carter. animation mechanics in SVG
-
Firstly, you aren't able to expose a private member as a parameter of a public method. Here's some working code:
Module Module1
Public Enum AnyEnum
a
b
End EnumPublic Sub Any(ByVal Enumeration As AnyEnum) End Sub Sub Main() Any(AnyEnum.a) End Sub
End Module
Does this help you? Cheers, Simon "The day I swan around in expensive suits is the day I hope someone puts a bullet in my head.", Chris Carter. animation mechanics in SVG
Thank's a lot for your quick response,Simon. I don't want to pass an enumerated value, but the enumeration itself, like this: Module Module1 Public Enum AnyEnum a b End Enum Public Sub Any(ByVal Enumeration As [Enum]) End Sub Sub Main() Any(??AnyEnum??) End Sub End Module Kind regards Hardy
-
Thank's a lot for your quick response,Simon. I don't want to pass an enumerated value, but the enumeration itself, like this: Module Module1 Public Enum AnyEnum a b End Enum Public Sub Any(ByVal Enumeration As [Enum]) End Sub Sub Main() Any(??AnyEnum??) End Sub End Module Kind regards Hardy
Try this:
Module Module1
Public Enum AnyEnum
a = 0
b = 1
End Enum
Public Sub Any(ByVal Enumeration As [Enum])Dim myenum As AnyEnum = CType(Enumeration, AnyEnum) Console.WriteLine(myenum.b) End Sub Sub Main() Console.WriteLine("before") Any(New AnyEnum()) Console.WriteLine("after") Console.ReadLine() End Sub
End Module
Hardy, I'm really interested to know ... why? ;) Cheers, Simon "The day I swan around in expensive suits is the day I hope someone puts a bullet in my head.", Chris Carter. animation mechanics in SVG