Opened 16 years ago
Closed 16 years ago
#1602 closed Feature Request (Rejected)
_ArrayMinIndex and Void entries
| Reported by: | Owned by: | ||
|---|---|---|---|
| Milestone: | Component: | AutoIt | |
| Version: | Severity: | None | |
| Keywords: | _ArrayMinIndex | Cc: |
Description
Thought I would just point out that for void entries, when calling _ArrayMinIndex, it always returns those entries. I was expecting it to throw an error if void entries were detected. As a result, I added a bit of code to the function so I could catch this:
; Search
If $iCompNumeric Then
For $i = $iStart To $iEnd
If $avArray[$i] = Chr(0) Then Return SetError(4, 0, -1)
If Number($avArray[$iMinIndex]) > Number($avArray[$i]) Then $iMinIndex = $i
Next
Else
For $i = $iStart To $iEnd
If $avArray[$i] = Chr(0) Then Return SetError(4, 0, -1)
If $avArray[$iMinIndex] > $avArray[$i] Then $iMinIndex = $i
Next
EndIf
A minor addition, but one I found to be helpful. It is, however, up to you on how you want to handle it.
Attachments (0)
Change History (7)
follow-up: 3 comment:1 by , 16 years ago
| Type: | Bug → Feature Request |
|---|
comment:3 by , 16 years ago
Replying to Jpm:
for me it is not a bug as Autoit do implicit conversion.
I move it to "feature request"
The issue is that sometimes if there are void entries, this can cause a program crash because _ArrayMin uses the min index as the subscript. Error output will catch this, stopping the crash. This is why I labeled bug, and not feature.
follow-up: 5 comment:4 by , 16 years ago
Why a program can crash just the return an "void" entry?
give me a good example of such crash
comment:5 by , 16 years ago
Replying to Jpm:
Here's a simplified example:
While $i <= 10
$array[$i] = $i
ToolTip("Lowest Value = " & _ArrayMin($array), 0,0)
WEnd
Related Functions _ArrayMinIndex, _ArrayMaxIndex, _ArrayMin, _ArrayMax.
Reason: Subscript Out Of Bounds
Related Example:
Func _ArrayMin(Const ByRef $avArray, $iCompNumeric = 0, $iStart = 0, $iEnd = 0) Local $iResult = _ArrayMinIndex($avArray, $iCompNumeric, $iStart, $iEnd) If @error Then Return SetError(@error, 0, "") '''Return $avArray[$iResult]''' EndFunc ;==>_ArrayMin
Bolded reasons.
Fix: add an error return on _ArrayMinIndex and _ArrayMaxIndex stated above.
comment:6 by , 16 years ago
It is over simplified as $array is not declared and $i not set too
can you put a real crashing example
Thanks
comment:7 by , 16 years ago
| Resolution: | → Rejected |
|---|---|
| Status: | new → closed |
I cannot imagine a real crash but just the script not working as you want.
If you really need to get error on such entries just check them before calling _ArrayMinIndex()

for me it is not a bug as Autoit do implicit conversion.
I move it to "feature request"