first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

Use of the VarType() Function with Optional Function Parameters

Since Optional function arguments are variants, the VarType() function should be used to "sub-type" these arguments for a non-variant data type. The sample code fragment below illustrates the form:

Public Sub OpenTextFile(FileName As String, _ Optional OpenWrite = False)

On Error GoTo HandleErr

'Check optional input.
If VarType(OpenWrite) <> vbBoolean Then Err.Raise 450

'More code may go here.

End Sub

Note the use of the instrinsic constant vbBoolean. For a complete list of contants refer to the online help documentation.

mod date: 1999-02-10T02:21:46.000Z