Opened on Jun 7, 2026 at 1:52:49 PM
#4101 closed Feature Request (Fixed)
Requesting consistency of the default value of $iStart/$iEnd in _Array* functions
| Reported by: | anonymous | Owned by: | Jpm |
|---|---|---|---|
| Milestone: | Component: | AutoIt | |
| Version: | Severity: | None | |
| Keywords: | _ArrayBinarySearch _ArrayFindAll _ArrayReverse _ArraySearch _ArrayShuffle _ArraySort _ArrayTrim | Cc: |
Description
Currently, the default value of $iStart/$iEnd/$iStart_Row/$iEnd_Row of the following _Array functions is 0 (zero):
_ArrayBinarySearch, _ArrayFindAll, _ArrayReverse, _ArraySearch, _ArrayShuffle, _ArraySort, _ArrayTrim
The default value of $iStart/$iEnd/$iStart_Row/$iEnd_Row of the following functions is -1:
_ArrayExtract, _ArrayMax, _ArrayMaxIndex, _ArrayMin, _ArrayMinIndex, _ArraySwap, _ArrayToClip, _ArrayToString
The inconsistency is one thing, but the more important thing is, zero is a valid value of index, right?
Consider this example:
Func FindSomething(ByRef $aArray, $sValue, $iStart, $iEnd) If Not IsArray($aArray) Or UBound($aArray) == 0 Then Return -1 If $iStart < 0 Then $iStart = 0 If $iEnd < 0 Then $iEnd = UBound($aArray) - 1 If $iEnd < $iStart Then Return -1 Local $iIndex = _ArraySearch($a, $sValue, $iStart, $iEnd) If @error Then Return -1 Return $iIndex EndFunc
This function's logic seems almost correct, except for when $iStart and $iEnd are 0.
Cases when calling FindSomething():
If
$iStart/$iEndare 1, it searches only$aArray[1], correct.
If$iStart/$iEndare 2, it searches only$aArray[2], correct.
If$iStart/$iEndare 0, it searches all items, incorrect.
That means, to make that function correct, the user has to individually handle the case of $iStart/$iEnd = 0 and write different code to search only the $aArray[0] for matches, how inconvenient 😒
And yeah, this may be a script breaking change if the user explicitly uses 0 as the default value instead of the keyword Default 😆
Attachments (0)
Change History (3)
comment:3 by , on Oct 21, 2026 at 1:15:23 PM
| Owner: | set to |
|---|---|
| Resolution: | → Fixed |
| Status: | new → closed |

Oh, a little typo in my example: