Hi,
shapper wrote:
I used the following code:
Public Enum Roles
End Enum
' Loop through each roles enumeration name
For Each role As String In Roles.GetNames(GetType(Roles))
MyFunction(role)
Next
This is working if MyFunction is as follows:
Function MyFunction(ByVal role As String)
However, I would like to use something like:
Function MyFunction(ByVal role As Roles)
to me it seems that you simply misunderstood something.
If you would like to have an argument in your function that is geared at an
enum, you should actually be fine with the way you did above. All you need
in order to use the enum in your function is a) from the caller, you need
to call it as in ClassName.EnumName.EnumValue and b) the function utilizing
the value must be within the enum's scope or the enum must also include the
complete path ([namespace], class-name, etc.).
Consider this:
public class MyClass
public enum MyEnum
MyValue1=1
MyValue2=2
end enum
public sub MyFunction(byval x as MyEnum) as boolean
select case x
case MyEnum.MyValue1
'...
case MyEnum.MyValue2
'...
case else
'...
end select
return ...
end sub
end class
A call to the above function from outside of MyClass could look like this:
dim cM as MyClass
dim XY as boolean=cm.MyFunction(MyClass.MyEnum.MyValue2)
Hence, is it possible that you took it the wrong way and there isn't any
need for GetNames ..? At least I don't see what you would need it for in
your scenario.
Cheers,
Olaf
--
My .02:
www.Resources.IntuiDev.com