Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking if a parameter is of the specified enumerated type

Status
Not open for further replies.

sergiog

Programmer
Feb 17, 2003
24
MT
Hi

am setting up an ADO connection string at runtime and i have a procedure accepting parameters for the commandtype and the commandtext.

I have set the commandtype as adCommandTypeEnum so that the intellisense comes up when calling the procedure.

how can i check that the passed parameter is actually one of the CommandType constants ??

Cheers
Sergio
 
You don't need to. If the caller were to pass an invalid value they would get an error (a big benefit of strong data-typing like you're doing).

If you had declared the parameter as a Long, then you would need to check, because the caller could have sent you any old value. But by declaring the parameter as type AdoCommandType, they can only send you a value in the enumeration.

Chip H.
 
Unfortunately not, chiph. Enums are not checked when passed as parameters to a sub or procedure, so it is certainly quite possible top pass unexpected values. Eg the following does not raise an error:

Option Explicit
Private Enum EnumeratedLongs
a = 1&
b = 2&
c = 3&
End Enum

Private Sub Command1_Click()
fred 3124
End Sub

Private Function fred(a As EnumeratedLongs) As Boolean
Debug.Print a
End Function

 
strongm,

do have an idea of how to stop that. i was thinking of checking that the return was one of the constants of the enum type. But that would defy the purpose coz i would still have to know the constants and write them down.

thanks
sergio.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top