views:

192

answers:

3

I am hoping to find a way to do this in vb.net:

Say you have function call getPaint(Color). You want the call to be limited to the parameter values of (red,green,yellow). When they enter that parameter, the user is provided the available options, like how a boolean parameter functions.

Any ideas?

+2  A: 

Hope I am not missing something from your question. Use an enumeration like this:

Enum Color
    Red = 1
    Green = 2
    Yellow = 3
End Enum

When you write getPaint(Color followed by a . (period) the Intellisense system will automatically suggest the three options declared in the enumeration (Red, Green, Yellow).

smink
+2  A: 

to limit a enum with a large number of values, to just a few you could do the following

C#

List<Color> allow = new List<Color> { Color.Red, Color.Green, Color.Yellow };
if (!allow.Contains(color))
{
    throw new ArguementException("Invalid Color");
}

VB

Dim allow As New List(Of Color)()
allow.Add(Color.Red)
allow.Add(Color.Green)
allow.Add(Color.Yellow)
If Not allow.Contains(color) Then
Throw New ArguementException("Invalid Color")
End If
Darren Kopp
A: 

Sweet! That is what I was looking for.

Thanks!

Chris

crathermel