Jump to content

_ArrayMinX() function (based on _ArrayMin() function)


Dirgi
 Share

Recommended Posts

_ArrayMinX() is an extension (I wrote) of the _ArrayMin() function.

Just beforehand: I'm using now AutoIT intemsively for just one week - So please have mercy when something is wrong or not done in the right way.

Why _ArrayMinX?:

When I used the _ArrayMin() function I did not receive the minimum value of my array caused to the issue that my array had some positions without any content.I allways received an empty value.

After some research on the internet I didn't find any answer to solve the problem, so I started to write my own function.

How does _ArrayMinX() work ?:

In a short sentence: When there is a MinValue, you'll receive it back :mellow:

I'll explain this with the following example:

This is my example Array:

Local $ExampleArray[19] = [2,"2",4,"25","0.34374374",1,6,"","A","x","","",12,70,"3","","7A","FE6","This is a test"]

As you can see, it contents a mix of numbers, alpanumerics and empty values like ""

When using now the _ArrayMin() function you'll always receive an empty value back which

might be correct from the computer calculation perspective but not really whant I want.

I would like to know the real minimum existing value, which can be i.e. a "1" or a "A"

So what does my function do?

1. Build a uniqueness with the function _ArrayUnique() to have each value just once.

(even an empty array appears now just once)

2. Sort the array with the _ArraySort() function. If there's now an empty Array it will

be the first in the sorted list ;-)

3. Now the function check if an empty array is existing and place the pointer on the right array

4. When asking for the Min Value I can additionally decide if I'd like to have my focus on an

numeric ar alpanumeric value.

Feel free to use the script.

I did already an implementation of the function on my <Array.au3> base script.

If you'd like to have it as well I just attached the content copy of my updated <Array.au3> script.

Cheers, Dirgi

Example Script: :)

#include <Array.au3>
Local $ExampleArray[19] = [2,"2",4,"25","0.34374374",1,6,"","A","x","","",12,70,"3","","7A","FE6","This is a test"]
Local $X
$X= _ArrayMinX($ExampleArray,0) ;Call the function
Msgbox (0,"",$X)
 
;---------------------------------------------------------------------------------------------------
 
Func _ArrayMinX(Const ByRef $AvArray, $iCompNumeric = 0 )
If Not IsArray($avArray) Then Return SetError(1, 0, -1)
Local $ArrayPointer, $AminX
$AminX = _ArrayUnique($avArray)     ;Compress the numbers of same contents (even arrays without content)
_ArraySort($AminX)                  ;Array without content (if existing) appears on top of sorted list ;-)
$ArrayPointer = 0
If $AminX[0] = "" Then $ArrayPointer = 1        ;If Array[0] has no content then set pointer to Array[1]
$AminX = _ArrayMin($AminX, $iCompNumeric, $ArrayPointer)
If @error Then Return SetError(@error, 0, "")
Return $AminX
EndFunc

Here is the implementation into <Array.au3>: (Only my part)

; #FUNCTION# ====================================================================================================================
; Name...........: _ArrayMinX
; Description ...: Returns the lowest value held in an array, even when there are some arrays without any content
; Syntax.........: _ArrayMinX(Const ByRef $avArray[, $iCompNumeric = 0)
; Parameters ....: $avArray     - Array to search
;               $iCompNumeric - [optional] Comparison method:
;               |0 - compare alphanumerically
;               |1 - compare numerically
; Return values .: Success - The minimum value in the array
;               Failure - "", sets @error (see _ArrayMinIndex() description for error codes)
; Author ........: Dirgi
; Modified.......:
; Remarks .......: Based on the scripting of the related functions
; Related .......: _ArraySort, _ArrayMinIndex, _ArrayMin, _ArrayUnique
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _ArrayMinX(Const ByRef $AvArray, $iCompNumeric = 0 )
If Not IsArray($avArray) Then Return SetError(1, 0, -1)
Local $ArrayPointer, $AminX
$AminX = _ArrayUnique($avArray)     ;Compress the numbers of same contents (even arrays without content)
_ArraySort($AminX)                  ;Array without content (if existing) appears on top of sorted list ;-)
$ArrayPointer = 0
If $AminX[0] = "" Then $ArrayPointer = 1        ;If Array[0] has no content then set pointer to Array[1]
$AminX = _ArrayMin($AminX, $iCompNumeric, $ArrayPointer)
If @error Then Return SetError(@error, 0, "")
Return $AminX
EndFunc

The complete updated <ARRAY.AU3> you'll find attached as compressed zip file.

ArrayAU3.zip

Edited by Dirgi
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...