CliftonL Posted April 27, 2014 Share Posted April 27, 2014 I have a problem that just started since AutoIt v3.3.11.4 was released. My script is modifying an xml file created in another program. It searches for the end of the <resources> section and adds some additional file references. However, this is now failing in v3.3.11.4 beta. Consider this code: $idx = _ArraySearch($xmlArr, "</resource>" 0, 0, 0, 1, 0) This code used to work in v3.3.11.3 and returned the last index of the $xmlArr where the search string was found. Now this fails with @error 6 which means the string was not found, while _ArrayDisplay() indicates the value IS located in the array. Since the file has some white space (tabs, etc) before the string, I think it may be failing because I'm not using a regular expression. However, the spec for the function indicates a stingInStr search is supposed to be performed. Has anyone else found this to be a problem? I changed to using _ArrayFindAll() and the script works again. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 28, 2014 Moderators Share Posted April 28, 2014 CliftonL, Can you please post an example of the array (or better the XML file and the code to convert it) and I will take look. It might take a while - I am currently using my phone on a cross-Channel ferry so I cannot run any code until I reach my destination later today. 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...
Moderators Melba23 Posted April 29, 2014 Moderators Share Posted April 29, 2014 CliftonL,I found the bug - the UDF was setting the search bounds after having reversed the limits when searching backwards. Swapping the order fixes it:expandcollapse popup#include <Array.au3> Global $aArray[5] = ["blah", "<resource>", "blah", "</resource>", "blah"] _ArrayDisplay($aArray, "", Default, 8) $iIndex = _ArraySearch_Mod($aArray, "</resource>", 0, 0, 0, 1, 1) ; start, end, case, compare, forward MsgBox($MB_SYSTEMMODAL, "Found forward", "Index: " & $iIndex) $iIndex = _ArraySearch_Mod($aArray, "</resource>", 0, 0, 0, 1, 0) ; start, end, case, compare, backward MsgBox($MB_SYSTEMMODAL, "Found backward", "Index: " & $iIndex) Func _ArraySearch_Mod(Const ByRef $avArray, $vValue, $iStart = 0, $iEnd = 0, $iCase = 0, $iCompare = 0, $iForward = 1, $iSubItem = -1, $bRow = False) If $iStart = Default Then $iStart = 0 If $iEnd = Default Then $iEnd = 0 If $iCase = Default Then $iCase = 0 If $iCompare = Default Then $iCompare = 0 If $iForward = Default Then $iForward = 1 If $iSubItem = Default Then $iSubItem = -1 If $bRow = Default Then $bRow = False If Not IsArray($avArray) Then Return SetError(1, 0, -1) Local $iDim_1 = UBound($avArray) - 1 If $iDim_1 = -1 Then Return SetError(3, 0, -1) Local $iDim_2 = UBound($avArray, $UBOUND_COLUMNS) - 1 ; Same var Type of comparison Local $bCompType = False If $iCompare = 2 Then $iCompare = 0 $bCompType = True EndIf ; Bounds checking If $bRow Then If UBound($avArray, $UBOUND_DIMENSIONS) = 1 Then Return SetError(5, 0, -1) If $iEnd < 1 Or $iEnd > $iDim_2 Then $iEnd = $iDim_2 If $iStart < 0 Then $iStart = 0 If $iStart > $iEnd Then Return SetError(4, 0, -1) Else If $iEnd < 1 Or $iEnd > $iDim_1 Then $iEnd = $iDim_1 If $iStart < 0 Then $iStart = 0 If $iStart > $iEnd Then Return SetError(4, 0, -1) EndIf ; Direction (flip if $iForward = 0) Local $iStep = 1 If Not $iForward Then Local $iTmp = $iStart $iStart = $iEnd $iEnd = $iTmp $iStep = -1 EndIf Switch UBound($avArray, $UBOUND_DIMENSIONS) Case 1 ; 1D array search If Not $iCompare Then If Not $iCase Then For $i = $iStart To $iEnd Step $iStep If $bCompType And VarGetType($avArray[$i]) <> VarGetType($vValue) Then ContinueLoop If $avArray[$i] = $vValue Then Return $i Next Else For $i = $iStart To $iEnd Step $iStep If $bCompType And VarGetType($avArray[$i]) <> VarGetType($vValue) Then ContinueLoop If $avArray[$i] == $vValue Then Return $i Next EndIf Else For $i = $iStart To $iEnd Step $iStep If $iCompare = 3 Then If StringRegExp($avArray[$i], $vValue) Then Return $i Else If StringInStr($avArray[$i], $vValue, $iCase) > 0 Then Return $i EndIf Next EndIf Case 2 ; 2D array search Local $iDim_Sub If $bRow Then ; Search rows $iDim_Sub = $iDim_1 If $iSubItem > $iDim_Sub Then $iSubItem = $iDim_Sub If $iSubItem < 0 Then ; will search for all Col $iSubItem = 0 Else $iDim_Sub = $iSubItem EndIf Else ; Search columns $iDim_Sub = $iDim_2 If $iSubItem > $iDim_Sub Then $iSubItem = $iDim_Sub If $iSubItem < 0 Then ; will search for all Col $iSubItem = 0 Else $iDim_Sub = $iSubItem EndIf EndIf ; Now do the search For $j = $iSubItem To $iDim_Sub If Not $iCompare Then If Not $iCase Then For $i = $iStart To $iEnd Step $iStep If $bRow Then If $bCompType And VarGetType($avArray[$j][$j]) <> VarGetType($vValue) Then ContinueLoop If $avArray[$j][$i] = $vValue Then Return $i Else If $bCompType And VarGetType($avArray[$i][$j]) <> VarGetType($vValue) Then ContinueLoop If $avArray[$i][$j] = $vValue Then Return $i EndIf Next Else For $i = $iStart To $iEnd Step $iStep If $bRow Then If $bCompType And VarGetType($avArray[$j][$i]) <> VarGetType($vValue) Then ContinueLoop If $avArray[$j][$i] == $vValue Then Return $i Else If $bCompType And VarGetType($avArray[$i][$j]) <> VarGetType($vValue) Then ContinueLoop If $avArray[$i][$j] == $vValue Then Return $i EndIf Next EndIf Else For $i = $iStart To $iEnd Step $iStep If $iCompare = 3 Then If $bRow Then If StringRegExp($avArray[$j][$i], $vValue) Then Return $i Else If StringRegExp($avArray[$i][$j], $vValue) Then Return $i EndIf Else If $bRow Then If StringInStr($avArray[$j][$i], $vValue, $iCase) > 0 Then Return $i Else If StringInStr($avArray[$i][$j], $vValue, $iCase) > 0 Then Return $i EndIf EndIf Next EndIf Next Case Else Return SetError(2, 0, -1) EndSwitch Return SetError(6, 0, -1) EndFunc ;==>_ArraySearch_ModThanks for pointing it out - as soon as I get back to an SVN-capable machine I will commit the change. 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...
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