rudi Posted November 19, 2020 Posted November 19, 2020 Hello, I've expected to get the resultcode to be -1 and @error set for this sample script: #include <Array.au3> #include <Debug.au3> Dim $a2Blockweise[1][3]=[[0]] Enum $iGroup,$iArrItems,$iSpace _DebugArrayDisplay($a2Blockweise,"Array defined") $NxPath="D:\BackupMSSQL" $ptr=_ArraySearch($a2Blockweise,$NxPath) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Ptr = ' & $Ptr & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console but it's $ptr=0 and not -1, and @error = 0, not 6 (value not found) >"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\temp\ArraySearch-test.au3" /UserParams +>13:07:26 Starting AutoIt3Wrapper v.18.708.1148.0 SciTE v.4.1.0.0 Keyboard:00000407 OS:WIN_2016/ CPU:X64 OS:X64 Environment(Language:0407) CodePage:0 utf8.auto.check:4 +> SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE UserDir => C:\Users\admin\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper SCITE_USERHOME => C:\Users\admin\AppData\Local\AutoIt v3\SciTE >Running AU3Check (3.3.14.5) from:C:\Program Files (x86)\AutoIt3 input:C:\temp\ArraySearch-test.au3 +>13:07:26 AU3Check ended.rc:0 >Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\temp\ArraySearch-test.au3" --> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop @@ Debug(12) : $Ptr = 0 >Error code: 0 +>13:07:33 AutoIt3.exe ended.rc:0 +>13:07:33 AutoIt3Wrapper Finished. >Exit code: 0 Time: 7.105 what do I miss? Earth is flat, pigs can fly, and Nuclear Power is SAFE!
rudi Posted November 19, 2020 Author Posted November 19, 2020 Strange behaviour, see this sample: #include <Array.au3> #include <Debug.au3> Dim $a2Blockweise[1][3]=[[0]] Enum $iGroup,$iArrItems,$iSize $a2Blockweise[0][0]=UBound($a2Blockweise)-1 _DebugArrayDisplay($a2Blockweise,"Array defined") $NxPath="nonsense" $ptr=_ArraySearch($a2Blockweise,$NxPath) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Ptr = ' & $Ptr & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console _ArrayAdd($a2Blockweise,"1|2|3") $a2Blockweise[0][0]=UBound($a2Blockweise)-1 _DebugArrayDisplay($a2Blockweise,"after ArrayAdd()") $ptr=_ArraySearch($a2Blockweise,$NxPath) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Ptr = ' & $Ptr & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console _ArrayDelete($a2Blockweise,$a2Blockweise[0][0]) $a2Blockweise[0][0]=UBound($a2Blockweise) - 1 _DebugArrayDisplay($a2Blockweise,"ArrayDelete()") $ptr=_ArraySearch($a2Blockweise,$NxPath) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Ptr = ' & $Ptr & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console is this WAD?🤨 Earth is flat, pigs can fly, and Nuclear Power is SAFE!
Developers Jos Posted November 19, 2020 Developers Posted November 19, 2020 Which part is strange in that last example? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
jchd Posted November 19, 2020 Posted November 19, 2020 The issue in the first post is with the $iCompare default setting ("string" = 0). 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)
Developers Jos Posted November 19, 2020 Developers Posted November 19, 2020 Guess you mean it should return in all 3 cases: $Ptr = -1 Error code: 6 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
rudi Posted November 22, 2020 Author Posted November 22, 2020 Exactly, I would have expectec $Ptr=-1 and @Error = 6. That in deed is fact, if the array has more rows. Just when it's "initialized" only, $Ptr=0 and @error = 0 Why? Earth is flat, pigs can fly, and Nuclear Power is SAFE!
Nine Posted November 22, 2020 Posted November 22, 2020 (edited) Your 2D array is 1 base but _ArraySearch is 0 base, you need to tell the function to start at 1. And as @jchd already told you. Using $iCompare = 0 => means "string" = 0, so result in first case shows success because [0][0] = 0. When you add 1 row, [0][0] = 1 and then there is no more 0 in first column. That explain why it returns failure for the second case. Third case, see case 1. If you use $iCompare = 2 (same type and same value) then the result is failure like you are expecting. #include <Array.au3> #include <Debug.au3> Dim $a2Blockweise[1][3]=[[0]] Enum $iGroup,$iArrItems,$iSize $a2Blockweise[0][0]=UBound($a2Blockweise)-1 _DebugArrayDisplay($a2Blockweise,"Array defined") $NxPath="nonsense" $ptr=_ArraySearch($a2Blockweise,$NxPath,1, 0, 0, 2) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Ptr = ' & $Ptr & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console _ArrayAdd($a2Blockweise,"1|2|3") $a2Blockweise[0][0]=UBound($a2Blockweise)-1 _DebugArrayDisplay($a2Blockweise,"after ArrayAdd()") $ptr=_ArraySearch($a2Blockweise,$NxPath,1, 0, 0, 2) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Ptr = ' & $Ptr & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console _ArrayDelete($a2Blockweise,$a2Blockweise[0][0]) $a2Blockweise[0][0]=UBound($a2Blockweise) - 1 _DebugArrayDisplay($a2Blockweise,"ArrayDelete()") $ptr=_ArraySearch($a2Blockweise,$NxPath,1, 0, 0, 2) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Ptr = ' & $Ptr & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console That is the way to properly use _ArraySearch... Edited November 22, 2020 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
rudi Posted November 22, 2020 Author Posted November 22, 2020 Thanks for all the explanations. now I got what @jchd pointed out, at least I think so: "The issue in the first post is with the $iCompare default setting ("string" = 0)." 0 Casting of variables to the same type (default), "string" = 0, "" = 0 or "0" = 0 match (If $iCase = 0) this means, with $iCompare = 0 the variable with the search string is converted (interpreded) to match the number 0. Basically, ANY string variable's content will match the number 0. What could that be good for?? For sure there is some benefit for this behaviour, otherwise it wouldn't be the default ... I don't get it ... ☹️ Earth is flat, pigs can fly, and Nuclear Power is SAFE!
jchd Posted November 22, 2020 Posted November 22, 2020 ConsoleWrite(("aaa" = 0) & @LF) ConsoleWrite(("0aaa" = 0) & @LF) ConsoleWrite(("1aaa" = 0) & @LF) ConsoleWrite(("123" = 123) & @LF) ConsoleWrite(("123" = 123.0) & @LF) If one of the argument to = is numeric and the other a string, the conversion from String to Number is implicit. Other comparison modes are more suited to your use case. 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)
Nine Posted November 22, 2020 Posted November 22, 2020 As I pointed out, you have two issues. 1- You have a 1-base 2D array that you are treating as a 0-base 2- You are not using the right type of comparaison method. 28 minutes ago, rudi said: What could that be good for?? The real question is, what are the right parameters to accomplish what I want to ? The good thing is there is an option for every (or close to every) type of requirements. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
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