Directly get an error description from the system

zhaozj2021-02-08  222

'Author: Thierry Waty' Home Author: http://www.geocities.com/ResearchTriangle/6311/ 'This is a description of the error from the system to get the error code directly in the program, you can not use hard-coded

'Example of use:

'Call Apierror

'*** or' debug.print returnapierror (53) '*** Return: Network adapter hardware error.

'#Vbideutils # **************************************************** ************** * Programmer Name: Waty Thierry '* Web Site: www.geocities.com/researchtriangle/6311/' * e-mail: waty.thierry@usa.net ' * Date: 12/10/1998 '* Time: 20:20' * module name: apierror_module '* module filename: apierror.bas' ****************** *********************************************************** '* Comments:' * This is a program that gets the error from the system directly from the system, you can use hard coded '*' * '***************** *********************************************************** ***

Option expedition

Private const format_message_from_system = & h1000private const format_message_ignore_inserts = & h200

Private Declare Function FormatMessage Lib "kernel32" Alias ​​"FormatMessageA" _ (ByVal dwFlags As Long, lpSource As Any, ByVal dwMessageId As Long, _ ByVal dwLanguageId As Long, ByVal lpBuffer As String, ByVal nSize As Long, _ Arguments As Long) As Long

'*** status cotsprivate const invalid_handle_value = -1 & private const error_success = 0 &

Public Function Returnapierror (ERRORCODE AS Long) AS String '#vbideutils # ***************************************************** ************************ * Programmer Name: Waty Thierry '* Web Site: www.geocities.com/researchtriangle/6311/' * e- Mail: waty.thierry@usa.net '* Date: 12/10/1998' * time: 20:21 '* module name: apierror_module' * module filename: apierror.bas' * procedure name: returnApierror '* parameters:' * ErrorCode As long '************************************************************** ********************************** '* Comments:' * takes an api error number, and returns '* a descriptive text string of the error' * '********************************************************** ********************* DIM SBUFFER AS STRING

'*** Allocate the string, then get the system to' *** tell us the error message associated with '*** this error number sBuffer = String (256, 0) FormatMessage FORMAT_MESSAGE_FROM_SYSTEM Or FORMAT_MESSAGE_IGNORE_INSERTS, 0 &, ErrorCode, 0 &, SBuffer, Len (Sbuffer), 0 &

'*** Strip The last null, THEEN THE LAST CRLF PAIR IF IT EXISTS SBUFFER = Left (Sbuffer, Instr (Sbuffer, Vbnullcha) - 1) IF Right $ (SBuffer, 2) = CHR $ (13) & chr $ 10) THEN SBUFFER = MID $ (SBuffer, 1, Len (SBuffer) - 2) endiff

ReturnapierRor = SBuffer

END FUNCTION

Public sub apierror () '#vbideutils # **************************************************** ****************** '* Programmer Name: Waty Thierry' * Web Site: www.geocities.com/researchtriangle/6311/ * e-mail: Waty.Thierry @ USA.NET '* DATE: 12/10/1998' * Time: 20:35 '* Module Name: Apierror_Module' * Module FileName: Apierror.bas' * procedure name: Apierror '* parameters:' ***** *********************************************************** ************** '* Comments:' * takes an api error number, and returns' * a descriptive text string of the error '*' ************* *********************************************************** ********** DIM SERROR AS STRING ON ERROR GOTO ERROR_APIERROR SERROR = INPUTBOX ("ENTER THE ERROR NUMBER", "Returns API Error") if ISNUMERIC (SERROR) = false The EXIT SUB MSGBOX RETURNAPIERROR (CLNG (serror), Vbinformation Vbokonly, "Error N" & SETROR EXIT SUB ERROR_APIERROR: MsgBox "Error N" & SERROR & VBCRLF & "Invalid Error Number" & vbcrlf & "You Have to Give Another One", Vbcritical Vbokonly, "Error N" & SEROR END SUB

转载请注明原文地址:https://www.9cbs.com/read-1949.html

New Post(0)