CVErr function
Summary
Converts an expression to the specified data type.
Syntax
CVErr(errornumber)
The required errornumber argument is any valid error number.
Example
Example
This example uses the CVErr function to return a Variant whose VarType is vbError (10). The user-defined function CalculateDouble returns an error if the argument passed to it isn't a number. Use CVErr to return user-defined errors from user-defined procedures or to defer handling of a run-time error. Use the IsError function to test if the value represents an error.
' Call CalculateDouble with an error-producing argument.
Sub Test()
Debug.Print CalculateDouble("345.45robert")
End Sub
' Define CalculateDouble Function procedure.
Function CalculateDouble(Number)
If IsNumeric(Number) Then
CalculateDouble = Number * 2 ' Return result.
Else
CalculateDouble = CVErr(2001) ' Return a user-defined error
End If ' number.
End Function
This example uses the CVErr function to return a Variant whose VarType is vbError (10). The user-defined function CalculateDouble returns an error if the argument passed to it isn't a number. Use CVErr to return user-defined errors from user-defined procedures or to defer handling of a run-time error. Use the IsError function to test if the value represents an error.
' Call CalculateDouble with an error-producing argument.
Sub Test()
Debug.Print CalculateDouble("345.45robert")
End Sub
' Define CalculateDouble Function procedure.
Function CalculateDouble(Number)
If IsNumeric(Number) Then
CalculateDouble = Number * 2 ' Return result.
Else
CalculateDouble = CVErr(2001) ' Return a user-defined error
End If ' number.
End Function