ancp Posted May 20, 2010 Share Posted May 20, 2010 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 More sharing options...
Moderators Melba23 Posted May 20, 2010 Moderators Share Posted May 20, 2010 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. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
jchd Posted May 20, 2010 Share Posted May 20, 2010 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 hereRegExp tutorial: enough to get startedPCRE 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 More sharing options...
ancp Posted May 20, 2010 Author Share Posted May 20, 2010 Thank to Melba23 and jchd. I needed that, both examples are great! I have to train BitAnd function Thanks again! Link to comment Share on other sites More sharing options...
jchd Posted May 20, 2010 Share Posted May 20, 2010 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 hereRegExp tutorial: enough to get startedPCRE 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 More sharing options...
ancp Posted May 20, 2010 Author Share Posted May 20, 2010 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 More sharing options...
MvGulik Posted May 20, 2010 Share Posted May 20, 2010 (edited) whatever Edited February 7, 2011 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 More sharing options...
jchd Posted May 20, 2010 Share Posted May 20, 2010 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 hereRegExp tutorial: enough to get startedPCRE 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 More sharing options...
MvGulik Posted May 21, 2010 Share Posted May 21, 2010 (edited) whatever Edited February 7, 2011 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 More sharing options...
MvGulik Posted May 21, 2010 Share Posted May 21, 2010 (edited) whatever Edited February 7, 2011 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 More sharing options...
jchd Posted May 21, 2010 Share Posted May 21, 2010 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 hereRegExp tutorial: enough to get startedPCRE 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now