naturelaws Posted October 1 Share Posted October 1 (edited) I am trying to use the _ArraySearch() function to trigger a condition when the 3rd element of $arrayTwo is not found in the $arrayOne. #include <Array.au3> local $arrayOne[3][2] $arrayOne[0][0] = UBound($arrayOne, 1)-1 $arrayOne[1][0] = "Notepad.exe" $arrayOne[1][1] = 1234 $arrayOne[2][0] = "Notepad.exe" $arrayOne[2][1] = 5678 _ArrayDisplay($arrayOne, "$arrayOne") local $arrayTwo[4][2] $arrayTwo[0][0] = UBound($arrayTwo, 1)-1 $arrayTwo[1][0] = "Notepad.exe" $arrayTwo[1][1] = 1234 $arrayTwo[2][0] = "Notepad.exe" $arrayTwo[2][1] = 5678 $arrayTwo[3][0] = "Notepad.exe" $arrayTwo[3][1] = 9101 _ArrayDisplay($arrayTwo, "$arrayTwo") for $x=1 to $arrayTwo[0][0] If Not _ArraySearch($arrayOne, $arrayTwo[$x][1], 0, 0, 0, 0, 1, 1) Then MsgBox(0, "", "Not Found element "&$arrayTwo[$x][1]&" in $arrayOne") EndIf next The above script does not trigger the MsgBox instruction. Please help me what am I doing wrong. Regards, Edited October 1 by naturelaws Link to comment Share on other sites More sharing options...
Nine Posted October 1 Share Posted October 1 As per help file of _ArraySearch Quote Success: the index that $vValue was found at. Failure: -1 and sets the @error flag to non-zero. You need to check @error because result of the function is always converted to True “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) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
jchd Posted October 1 Share Posted October 1 7 hours ago, naturelaws said: For $x=1 to $arrayTwo[0][0] If _ArraySearch($arrayOne, $arrayTwo[$x][1], 0, 0, 0, 0, 1, 1) < 0 Then MsgBox(0, "", "Not Found element "&$arrayTwo[$x][1]&" in $arrayOne") EndIf Next 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...
Moderators Melba23 Posted October 3 Moderators Share Posted October 3 Moved to the appropriate AutoIt General Help and Support forum, as the Developer General Discussion forum very clearly states: Quote General development and scripting discussions. Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums. Moderation Team 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...
Deye Posted October 3 Share Posted October 3 This is the method that I would employ. For $x = 1 To $arrayTwo[0][0] If _ArraySearch($arrayOne, $arrayTwo[$x][1], 0, 0, 0, 0, 1, 1) * -1 > 0 Then MsgBox(0, "", "Not Found element " & $arrayTwo[$x][1] & " in $arrayOne") EndIf Next Link to comment Share on other sites More sharing options...
jchd Posted October 4 Share Posted October 4 (edited) @Deye you got the comparison wrong: if a match is found, the index of the found array element is returned, which is >= 0, else no match returns -1, which as you know is < 0. EDIT: sorry I looked too fast, focussing on the > 0 only. My bad. Edited October 4 by jchd 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...
pixelsearch Posted October 4 Share Posted October 4 (edited) Hello everybody There are a couple of things I don't understand in this thread, could you please explain, thanks. On 10/1/2024 at 11:42 AM, Nine said: You need to check @error because result of the function is always converted to True @Nine What does it mean exactly ? Return of the function is -1 when it fails, so what is always converted to True ? @jchd I always script it a bit like you (in your 1st post) i.e. check first the result of _ArraySearch ( >= 0 means found) If it's not >= 0, then only I'd check @error to display the @error value in a MsgBox etc... 7 hours ago, jchd said: Deye, you got the comparison wrong [...] Why is that ? It seems to me that Deye's way returns correct results (see script below) but he could make it easier. @Deye why the complication of "* -1 > 0" Isn't it simpler to check it with "<0" when it fails (which is equivalent to the "-1" indicated in the help file) ? Test script : #include <Array.au3> Local $aArray[5] = [2, 50, -4, 0, 10] For $i = 0 To 2 $iIndex = _ArraySearch($aArray, $i) ; 0+ if found, -1 if not found If $iIndex = -1 Then ConsoleWrite("Element " & $i & " not found in array" & @crlf) Else ConsoleWrite("Element " & $i & " found in array (index = " & $iIndex & ")" & @crlf) EndIf Next ConsoleWrite("-----" & @crlf) For $i = 0 To 2 If _ArraySearch($aArray, $i) * -1 > 0 Then ConsoleWrite("Deye's way : Not Found element " & $i & " in array" & @crlf) EndIf Next Guys, please don't get mad at me if I wrote something wrong, in case I missed something that is obvious to you. Thanks for reading. Edited October 4 by pixelsearch typo Link to comment Share on other sites More sharing options...
jchd Posted October 4 Share Posted October 4 1 hour ago, pixelsearch said: Why is that ? It seems to me that Deye's way returns correct results (see script below) but he could make it easier. Post edited: I did see the * -1 part (and didn't expect it), just the > 0 caught my (olding) eyes. 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...
pixelsearch Posted October 4 Share Posted October 4 @jchd @Nine I guess I understand what you meant, as -1 means True when tested like the following, as it happens in nearly all functions that return 1 when success : If $iRet Then ; will be True no matter $iRet > 0 or < 0 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