crashdemons Posted December 31, 2009 Share Posted December 31, 2009 (edited) Edit: This issue was misunderstanding a function because the documentation did not match the function. Please see post #4.I am using AutoIt 3.3.2.0 from the installer.Here is a short reproducer (most of the length is just the array):#include <Array.au3> #Region ArrayDeclared Global $ChatSettings[10][2] = [ _ ['ProtoVer', 102], _ ['Server', 'cs105.msg.sp1.yahoo.com'], _ ['ServerAddr', ''], _ ['Port', 5050], _ ['Username', 'Not_Connected'], _ ['Password', ''], _ ['Room', 'Programming:1::1012'], _ ['Autoconnect', 0], _ ['Autojoin', 1], _ ['AutoCloak', 0]] #EndRegion ArrayDeclared #Region ArraySearch Global $iIndex=_ArraySearch($ChatSettings,'WindowCoords') Global $iError=@error #EndRegion ArraySearch MsgBox(0,'Debug Output','Index Found: '&$iIndex&@CRLF&'Error: '&$iError)What I got:"Index Found: 7Error: 0"What I Expected:"Index Found: -1Error: 6"As you can see in the code, I am searching for "WindowCoords" which does not exist in the Array; according to the help-file, Partial search is disabled by default and the default search column/subitem is 0. ... So why is it "matching" the '0' in element 7, column 1?Hopefully this is not just me being stupid again, but I cannot see anything documenting this type of behavior. From the help file:_ArraySearch(Const ByRef $avArray, $vValue [, $iStart = 0 [, $iEnd = 0 [, $iCase = 0 [, $iPartial = 0 [, $iForward = 1 [, $iSubItem = 0]]]]]]) Edited December 31, 2009 by crashdemons My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.) Link to comment Share on other sites More sharing options...
funkey Posted December 31, 2009 Share Posted December 31, 2009 I think this is a bug. Is always matches the first 0 in the second dimension that is no string, if the search does not match anything. It has nothing to do with the 0 in WindowCoords0.It has something to do with that behavior:If 0 = "" Then MsgBox(0,"0","") If Int(0) = "" Then MsgBox(0,"Int","") If String(0) = "" Then MsgBox(0,"String","") Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning. Link to comment Share on other sites More sharing options...
crashdemons Posted December 31, 2009 Author Share Posted December 31, 2009 (edited) I think this is a bug. Is always matches the first 0 in the second dimension that is no string, if the search does not match anything. It has nothing to do with the 0 in WindowCoords0. It has something to do with that behavior: If 0 = "" Then MsgBox(0,"0","") If Int(0) = "" Then MsgBox(0,"Int","") If String(0) = "" Then MsgBox(0,"String","") Updated the first post; I have tested and agree that the "0" on the end of "WindowCoords0" and the matching '0' is a coincidence but should still not be matching that element. Thanks. However, I don't agree that your code is relevant to the issue. Number comparison: the value of 0 is 0, the value of "" is 0; True Number comparison: the value of Int(0) is 0, the value of "" is 0; True String comparison: the value of String(0) is "0", the value of "" is ""; False Yes, "WindowCoords0"=0 would be True - explaining why "WindowCoords0" matches the Integer 0 - but it does not explain why _ArraySearch was searching the second dimension in the first place, since the default 'Sub-Index' is 0 (first Dimension). ...[, $iSubItem = 0]... $iSubItem [optional] Sub-index to search on in 2D arrays Edited December 31, 2009 by crashdemons My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.) Link to comment Share on other sites More sharing options...
crashdemons Posted December 31, 2009 Author Share Posted December 31, 2009 (edited) Aha...The help file documentation (and the function comments) do not match the function definition.Array.au3 excerpt:; #FUNCTION# ==================================================================================================================== ; Name...........: _ArraySearch ; Description ...: Finds an entry within a 1D or 2D array. Similar to _ArrayBinarySearch(), except that the array does not need to be sorted. ; Syntax.........: _ArraySearch(Const ByRef $avArray, $vValue[, $iStart = 0[, $iEnd = 0[, $iCase = 0[, $iPartial = 0[, $iForward = 1[, $iSubItem = 0]]]]]]) ; Parameters ....: $avArray - The array to search ; $vValue - What to search $avArray for ; $iStart - [optional] Index of array to start searching at ; $iEnd - [optional] Index of array to stop searching at ; $iCase - [optional] If set to 1, search is case sensitive ; $iPartial - [optional] If set to 1, executes a partial search ; $iForward - [optional] If set to 0, searches the array from end to beginning (instead of beginning to end) ; $iSubItem - [optional] Sub-index to search on in 2D arrays ; Return values .: Success - The index that $vValue was found at ; Failure - -1, sets @error: ; |1 - $avArray is not an array ; |2 - $avArray is not a 1 or 2 dimensional array ; |4 - $iStart is greater than $iEnd ; |6 - $vValue was not found in array ; |7 - $avArray has too many dimensions ; |(3, 5 - Deprecated error codes) ; Author ........: SolidSnake <MetalGX91 at GMail dot com> ; Modified.......: gcriaco <gcriaco at gmail dot com>, Ultima - 2D arrays supported, directional search, code cleanup, optimization ; Remarks .......: This function might be slower than _ArrayBinarySearch() but is useful when the array's order can't be altered. ; Related .......: _ArrayBinarySearch, _ArrayFindAll ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _ArraySearch(Const ByRef $avArray, $vValue, $iStart = 0, $iEnd = 0, $iCase = 0, $iPartial = 0, $iForward = 1, $iSubItem = -1) If Not IsArray($avArray) Then Return SetError(1, 0, -1) If UBound($avArray, 0) > 2 Or UBound($avArray, 0) < 1 Then Return SetError(2, 0, -1)So we see that while the help file and the comments indicate the default subindex is 0, for the first dimension, it is actually defaulted as -1, for searching ALL subindices. Edit: This issue is solved for my purposes by changing the last parameter to 0, but the documentation still needs updating...Edit: adding a ticket about the documentation...Edit: ticket added: #1381 Edited December 31, 2009 by crashdemons My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.) 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