Custom parameters values

rjjebs

Member
Joined
Feb 7, 2007
Messages
10
Programming Experience
5-10
I have created a function that I would like to have other developers use in their code, one of the function parameters can have 1 of several possible valid values. Is there a way when another developer references this function in their code when they are filling in the parms values to display back to them a vaild selection custom list of values to choose from (like Intellisense)
 
Yes, using an enumeration, defined in code as Enum. Example:
VB.NET:
Public Enum myOptions
   option1
   option2
   option3
End Enum
This enumeration can used as parameter type:
VB.NET:
Public Sub method(ByVal parameter As myOptions)
 
End Sub
Not just for method, any variable can be declared as this type:
VB.NET:
Dim x As myOptions
To combine enum values you have to mark it with the flags attribute and give each member a value to the powers of two:
VB.NET:
<Flags()> PublicEnum myOptions
   none = 0
   option1 = 1
   option2 = 2
   option3 = 4
EndEnum
Then use bitwise operators to work with combinations of this value:
VB.NET:
Dim x As myOptions = myOptions.option1 Or myOptions.option2
 
' x is now both value option1 and value option2
' if you show this value as string with x.ToString() it will read "option1, option2"
 
Back
Top