"hharry" <pa*********@nyc.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Is it possible to force a function argument to fall with a range of
values ?
That's what coding is for ... ;-)
I have a function which searches a database table and accepts a
query type argument which I would like to be either 1 or 0.
In this particular case, you could /suggest/ values by using an Enum,
as in
Public Enum QueryType
[Type0] = 0
[Type1] = 1
End Enum
Public Function IsFound( _
ByVal eaType as QueryType _
, ByVal sName As String _
) as ??? ' Option Strict On /please/
But that *doesn't* guarantee that you're /always/ going to get one
of those values - since Enums are boiled down to Integers at compile
time, you could /still/ get some awkward .. Soul who manages to foist
the value 37 on your poor, defenceless Function. So you code
"defensively" :
Public Function IsFound( _
ByVal eaType as QueryType _
, ByVal sName As String _
) as ??? ' Option Strict On /please/
If Not [Enum].IsDefined(GetType(QueryType), eaType) Then
Throw New ArgumentException( ...
End If
' Do the real work here
End Function
HTH,
Phill W.