Export (0) Print
Expand All

ErrorToString Function

Returns the error message that corresponds to a given error number.

Public Shared Function ErrorToString(ByVal errornumber As Integer) As String

Parameter

errornumber
Optional. Any valid error number.

Exceptions/Errors

Exception type Error number Condition
ArgumentException 5 ErrorNumber is out of range.

Remarks

The ErrorToString function examines the property settings of the Err object to identify the most recent run-time error. The return value of the ErrorToString function corresponds to the Description property of the Err object. If errornumber is a valid error number but is not defined, ErrorToString returns the string, "Application-defined or object-defined error." If errornumber is not valid, an error occurs. If errornumber is omitted, the message corresponding to the most recent run-time error is returned. If no run-time error has occurred, or errornumber is 0, ErrorToString returns a zero-length string ("").

In Visual Basic version 6.0 and earlier, this functionality was provided by the Error function.

Example

The following code uses the ErrorToString function to display error messages that correspond to the specified error numbers:

Dim ErrorNumber As Integer
For ErrorNumber = 61 To 64   ' Loop through values 61 - 64.
   MsgBox(ErrorToString(ErrorNumber))   ' Display error names in message box.
Next ErrorNumber

Requirements

Namespace: Microsoft.VisualBasic

Module: Conversion

Assembly: Microsoft Visual Basic .NET Runtime (in Microsoft.VisualBasic.dll)

See Also

Err Object | Description Property | Structured Exception Handling | Unstructured Exception Handling | ArgumentException Class

Show:
© 2014 Microsoft