Jump to content

Error code number decomposition


Recommended Posts

Hello, can someone please advise, how to work with functions BitAND and BitOR for decomposition any numeric values? My idea is sum of the error numbers into a single number (like mysql ODBC option).

Global $ERR_NUMBER
Global $ERR_MISSING_FILE    = 1
Global $ERR_WRONG_FORMAT    = 2
Global $ERR_WRONG_CODEPAGE  = 4
Global $ERR_WRONG_FILENAME  = 8
Global $ERR_WRONG_NUMLINE   = 16
...

_check_file("c:\test.tlc")


; whats errors? <<==
    ...
    code for obtaining the partial values $ERR_NUMBER
    ...
    ;I need get all occurrence errors
    ; maybe with BitAND?


Func _check_file($sFile)
    If ... Then $ERR_NUMBER += $ERR_MISSING_FILE
    If ... Then $ERR_NUMBER += $ERR_WRONG_FORMAT
    IF ...
    
    ; write err number to db
    ...
EndFunc
Link to comment
Share on other sites

  • Moderators

ancp,

I would do it like this:

Global $ERR_NUMBER = 31 ; Change this and watch the returned errors change

Global $ERR_LIST[5] = ["MISSING_FILE", "WRONG_FORMAT", "WRONG_CODEPAGE", "WRONG_FILENAME", "WRONG_NUMLINE"]

For $i = 0 To 4
    $ERR_CHECK = 2^$i
    If BitAND($ERR_NUMBER, $ERR_CHECK) = $ERR_CHECK Then ConsoleWrite("Error Number " & $i + 1 & " - " & $ERR_LIST[$i] & @CRLF)
Next

Using an array makes the whole thing much neater. :idea:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I understand it that you need to _test_ bit-coded error flags.

I'd do it this way:

Global Enum $ERR_MISSING_FILE   = 1, _
            $ERR_WRONG_FORMAT   = 2, _
            $ERR_WRONG_CODEPAGE = 4, _
            $ERR_WRONG_FILENAME = 8, _
            $ERR_WRONG_NUMLINE = 16

Local $errcode = 13     ; say you receive this value

If BitAND($errcode, $ERR_MISSING_FILE) <> 0 Then MsgBox(0,"Error", "Missing file!")
If BitAND($errcode, $ERR_WRONG_FORMAT) <> 0 Then MsgBox(0,"Error", "Wrong format!")
If BitAND($errcode, $ERR_WRONG_CODEPAGE) <> 0 Then MsgBox(0,"Error", "Wrong codepage!")
If BitAND($errcode, $ERR_WRONG_FILENAME) <> 0 Then MsgBox(0,"Error", "Wrong file name!")
If BitAND($errcode, $ERR_WRONG_NUMLINE) <> 0 Then MsgBox(0,"Error", "Wrong numline!")
If BitAND($errcode, BitNOT(BitOR($ERR_MISSING_FILE, $ERR_WRONG_FORMAT, $ERR_WRONG_CODEPAGE, $ERR_WRONG_FILENAME, $ERR_WRONG_NUMLINE))) <> 0 Then MsgBox(0,"Error", "Unexpected unspecified error!")

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Both solutions have advantages: Melba's is compact and less verbose, but mine won't burst if you have to deal with error codes which are not in an increasing power of 2 sequence, or coumpound values, like 0x0C40.

In AutoIt like in Perl: "There is more than one way to do it!"

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

I agree. Also important is the speed of the algorithm, it is necessary to check many many files. I think the cumulative error is a good solution. Both variants certainly applies in the future.

Link to comment
Share on other sites

whatever Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

Try an array with index an increasing power of 2 and those error codes:

Global Enum $ERR_MISSING_FILE = 1, _
 $ERR_WRONG_FORMAT = 4, _
 $ERR_WRONG_CODEPAGE = 0x0208, _
 $ERR_WRONG_FILENAME = 0x0082, _
 $ERR_WRONG_NUMLINE = 0x0C40

There are a large number of contexts where status codes don't map on single bits individually.

Don't believe I dismiss Melba's approach in any way. I was only offering another way and it's up to the reader to select the most suitable approach.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

whatever Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

whatever Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

Sorry if I didn't use the right term. What I was intending is that, for ease of maintenance and robustness, I'd favor another approach as there is little or no guarantee that newly added constants will still be single bit. It's too easy to add new constants at the head of a file, forgetting that the code won't cope with them. This can lead to weird errors waiting for the right time to bite you at the most sensible spot between the legs: rare errors going undetected by clever code crafted to catch them all.

Without throwing bad words to Melba (someone I greatly appreciate) I wouldn't use this algorithm to scan for error codes in the general situation for my own durable code. It's nothing personal: I've writen fragile code myself and still do on occasion!

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...