Jump to content
Sign in to follow this  
Dirgi

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

Recommended Posts

Dirgi

_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

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • MrCheese
      By MrCheese
      hi all,
      reviewing the forum, this thread is applicable: 
       
       
      I wanted to know if there is now a better way to do this?
      In essence, I load a tab delimited txt file into an array (works well). I used tab, as some fields in the original csv contains commas.
      However, I needed autoit to manipulate this array, and output it as a csv.
      IF my array contains items with a comma, without double quotes around the field, then how best do I get a csv out of this?
      My current workaround is to filewritefromarray tab delimited, then open it in excel and save as a csv. I will need to check this to see how the address fields behave that contain a comma.
       
      Any thoughts would be appreciated.
       
    • Skeletor
      By Skeletor
      Hi All,

      I would like to know how you would take a FileLineRead and insert it into an array which then inserts it into Excel?
      One thing to know is the files content is broken up, so I only use half of the content within $FileRead1.
      So its imperative that the $value1, $value2, etc variables be used. 
      Code below:
      $FileRead1 = FileReadLine("C:\temp\sample.txt",1) For $count = 1 To _FileCountLines($FileRead1) Step 1 $string = FileReadLine($FileRead1, $count) $input = StringSplit($string, ",", 1) $value1 = $input[1] $value2 = $input[2] $value3 = $input[3] $value4 = $input[4] _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value1, "A1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value2, "B1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value3, "C1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value4, "D1") Next  
    • ademon
      By ademon
      Hi. I can open the editor with out problems but I can not compile because it is placed on another partition diferent from C.
      Can you provide an update of this bug?


    • AnonymousX
      By AnonymousX
      Hello,
      I'm trying to write a script that moves copies excel cells into an array. I'll than manipulate the values and send array into another program. 
      I don't want range to be specific to a workbook, or sheet, or set of cells.
      I want user to be able to highlight desired cells and to copy either normally ("Ctrl+C") or by a hotkey ("Alt+C"). 
      Could someone help me with this?
      Thank you,
      I've tried to write the framework: (edited)
      #include <MsgBoxConstants.au3> #include <Array.au3> #include <Excel.au3> HotKeySet("!v", "Pastedata") While True Sleep(1000) WEnd func Makearray() local $bArray ;User has cells already copied ;Convert clipboard into an array ;I don;t know how excel stores data to clipboard so don;t know how to bring it into array _Arraydisplay($bArray) MsgBox(0,0,$bArray) return $bArray endfunc func Pastedata() Local $aArray MsgBox(0,0,"wait",1) ;make array based on assumption user has already copied a range to clipboard $aArray = Makearray() ;paste code ;don;t worry about this I got the rest endfunc  
    • lenclstr746
      By lenclstr746
      Hi guys,
      Some functions of my script are running slowly. Very slow. What is the reason?
      My Code:
      <snip>
×