Merged Error Code Technique

Introduction

  Coding in PowerBASIC (PB), either in PB For Windows (PBWin) or in PB Console Compiler (PBCC), we may need to work with Windows error codes, PB error codes, or both in one program. This means two seperate places to find a description for the error. I am proposing one 8 digit hexadecimal code number for any error reported in your program. Seems to me this would be especially useful when writing for other end users. (Simple pin-point reporting.)

  The on-line documentation for Windows API functions say use GetLastError1 to get error information, which retrieves the last error code for that thread. These codes are 32 bit. If bit 29 is 0 it is a Windows error code, when set it is an application-defined error code. The last used value is 15841 (within 16 bits), but needing bit 29 means 32 bit. The GetLastError page says it returns a DWORD. Note - WinBase.inc defines return as LONG, that needs to be changed to DWORD; if you use José Roca's includes check there too. (Remember mention of bit 29 and DWORD.)

 Visual Basic for Application (VBA) error codes2 appear to be 16 bit, and the code numbers have no relation to the Windows error codes. I said "appears" because the list is alphabetical, and scanning by eye shows codes greater than 255 but none greater than 65535. With VBA being a Windows application Microsoft could have (IMO) set bit 29 and had a consolidated group of error codes. But they didn't. (So why bring up VBA error codes? Read on.)

  PB run-time error codes3 are a sparse subset of the VBA error code set that is itself sparse (some values skipped). "Subset" also because only values 255 or lower are used (8 bit). The PB compile-time errors (401-640) have no relation with VBA error codes of the same range. PB is a Windows application for creating Windows applications. PB itself reserves run-time error codes 151 to 240 for user assigned error codes in PB programs.

Proposal

To use the upper nibble

FormatMessage3


Source Code

Full copyleft (ɔ), 2023 by Dale Yarker in source or compiled form. Complete license in new tab or window.

xxx


Back Matter

1 learn.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-getlasterror
2 learn.microsoft.com/en-us/office/vba/language/reference/error-messages
3 learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-formatmessage

Created on 17 Jun 2023, last edit 19 Jun 2023.

To Domain Home.

home
To Dale's Notebook index.
notebook
To Programs index.
programs