Modify

#4101 new Feature Request

Requesting consistency of the default value of $iStart/$iEnd in _Array* functions

Reported by: anonymous Owned by:
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/$iEnd are 1, it searches only $aArray[1], correct.
If $iStart/$iEnd are 2, it searches only $aArray[2], correct.
If $iStart/$iEnd are 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 (2)

comment:1 by anonymous, on Jun 7, 2026 at 1:59:06 PM

Oh, a little typo in my example:

	Local $iIndex = _ArraySearch($aArray, $sValue, $iStart, $iEnd)

comment:2 by TicketCleanup, on Jun 7, 2026 at 2:00:01 PM

Version: 3.3.18.0

Automatic ticket cleanup.

Modify Ticket

Action
as new The ticket will remain with no owner.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.