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

## 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

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
; 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

## Create an account

Register a new account

• ### Similar Content

• By Hermes
My _Excel_RangeCopyPaste is not working as intended. What I am trying to accomplish is copy the range B:E using _Excel_RangeCopyPaste in the first row and repeat the same for row 2 and so on.
;Skip from reading header columns Local \$Skipline = 0 ;0==> first line Local \$temprf For \$i = 0 To UBound(\$aArray2) - 1 If \$Skipline = \$i Then ContinueLoop \$temprf &= \$aArray2[\$i] _Excel_RangeCopyPaste(\$oWorkbook.Activesheet, \$oRange) Local \$oTest = _WD_FindElement(\$sSession, \$_WD_LOCATOR_ByCSSSelector, "PasteButton") ;This button will paste values from the Clipboard once clicked _WD_ElementAction(\$sSession, \$oTest, 'click')) Next Here's the full code:
#Include <Chrome.au3> #Include <wd_core.au3> #Include <wd_helper.au3> #Include <WinHttp.au3> #include <MsgBoxConstants.au3> #include <IE.au3> #include <Array.au3> #include <Excel.au3> Local \$sDesiredCapabilities, \$sSession SetupChrome() _WD_Startup() \$sSession = _WD_CreateSession(\$sDesiredCapabilities) _WD_LoadWait(\$sSession) _WD_Navigate(\$sSession, "test.html") Local \$oAppl = _Excel_Open() Local \$sWorkbook = "test.xlsx" Local \$oWorkbook = _Excel_BookOpen(\$oAppl, \$sWorkbook) ;open excel and pass both parameters Local \$aArray2 = _Excel_RangeRead(\$oWorkbook,Default,\$oWorkbook.ActiveSheet.Usedrange.Columns("A:A")) Local \$oRange = \$oWorkbook.ActiveSheet.Range("B:E") ;Skip from reading header columns Local \$Skipline = 0 ;0==> first line Local \$temprf For \$i = 0 To UBound(\$aArray2) - 1 If \$Skipline = \$i Then ContinueLoop \$temprf &= \$aArray2[\$i] _Excel_RangeCopyPaste(\$oWorkbook.Activesheet, \$oRange) Local \$oTest = _WD_FindElement(\$sSession, \$_WD_LOCATOR_ByCSSSelector, "PasteButton") ;This button will paste values from the Clipboard once clicked _WD_ElementAction(\$sSession, \$oTest, 'click')) Next _WD_Shutdown() Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') Return '{"capabilities":{"alwaysMatch":{"goog:chromeOptions":{"w3c":true,' & _ '"excludeSwitches":["enable-automation"],"useAutomationExtension":false}}}}' EndFunc ;==>SetupChrome For the first row I am trying to copy just B:E with the following info
Apple Banana Orange Mango and then repeat for row 2, row 3, etc. I've attached the spreadhseet.
test.xlsxI have also attached the excel file for reference.

• This topic give you access to an AutoIt functions library I maintain which is called PAL, Peter's AutoIt Library. The latest version 1.25 contains 212 functions divided into these topics:
window, desktop and monitor GUI, mouse and color GUI controls including graphical buttons (jpg, png) logics and mathematics include constants string, xml string and file string dialogues and progress bars data lists: lists, stacks, shift registers and key maps (a.ka. dictionaries) miscellaneous: logging/debugging, process and system info Change log and files section  on the PAL website (SourceForge).
A lot of these functions were created in the development of Peace, Peter's Equalizer APO Configuration Extension, which is a user interface for the system-wide audio driver called Equalizer APO.
• By Hermes
I have an html table that displays data along with an excel spreadsheet that has the same data as the html table. I am wanting to only match the Title column in my html table with the Title column in my Excel spreadsheet. If the titles match, click on the Edit hyperlink and continue to loop to next row. The issue I'm experience is its not matching correctly. So far  i've written the codes below:
<table border="1" class="test"> <tr> <th> UniqueID</th> <th> Title</th> <th> UserID</th> <th> Address</th> <th> Gender </th> </tr> <tr> <td> 1 </td> <td> Title1 </td> <td> 12345 </td> <td> Manila </td> <td> <span> Male </span> </td> </tr> <tr> <td align="center" colspan="5"> <a href="#" class="testlink">Edit</a> </td> </tr> <tr> <td> 2 </td> <td> Title2 </td> <td> 67891 </td> <td> Valenzuela </td> <td> <span> Female </span> </td> </tr> <tr> <td align="center" colspan="5" > <a href="#" class="testlink">Edit</a> </td> </tr> <tr> <td> 3 </td> <td> Title3 </td> <td> 88888 </td> <td> Ohio </td> <td> <span> Male </span> </td> </tr> <tr> <td align="center" colspan="5" > <a href="#" class="testlink">Edit</a> </td> </tr> <tr> <td> 4 </td> <td> Title4 </td> <td> 77777 </td> <td> California </td> <td> <span> Female </span> </td> </tr> <tr> <td align="center" colspan="5" > <a href="#" class="testlink">Edit</a> </td> </tr> <tr> <td> 5 </td> <td> Title5 </td> <td> 33333 </td> <td> Arizona </td> <td> <span> Male </span> </td> </tr> <tr> <td align="center" colspan="5" > <a href="#" class="testlink">Edit</a> </td> </tr> </table> #Include "Chrome.au3" #Include "wd_core.au3" #Include "wd_helper.au3" #Include "Excel.au3" #Include "_HtmlTable2Array.au3" #Include "Array.au3" Local \$sDesiredCapabilities, \$sSession SetupChrome() _WD_Startup() \$sSession = _WD_CreateSession(\$sDesiredCapabilities) _WD_LoadWait(\$sSession) _WD_Navigate(\$sSession, "index.html") Sleep(6000) Local \$oExcel = _Excel_Open() Local \$oWorkbook = _Excel_BookOpen(\$oExcel, "test.xlsx") ; Get the table element \$sElement = _WD_FindElement(\$sSession, \$_WD_LOCATOR_ByXPath, "//table[@class='test']") ; Retrieve HTML \$sHTML = _WD_ElementAction(\$sSession, \$sElement, "Property", "outerHTML") ;Local \$aTable = _HtmlTableGetWriteToArray(\$sHTML) Local \$aArray1 = _Excel_RangeRead(\$oWorkbook,1,\$oWorkbook.ActiveSheet.Usedrange.Columns("B:B")) Local \$aArray2 = _HtmlTableGetWriteToArray(\$sHTML) ;_ArrayDisplay(\$aArray1) ;_ArrayDisplay(\$aArray2) For \$i = UBound(\$aArray1) - 1 To 0 step - 1 For \$j = UBound(\$aArray2) - 1 to 0 step - 1 If \$aArray1[\$i][1] == \$aArray2[\$j][1] Then _WD_WaitElement(\$sSession, \$_WD_LOCATOR_ByXPath, "//a[contains(@class,'testlink') or contains(text(),'Edit')]") \$test1 = _WD_FindElement(\$sSession, \$_WD_LOCATOR_ByXPath, "//a[contains(@class,'testlink') or contains(text(),'Edit')]") _WD_ElementAction(\$sSession, \$test1, 'click') ;_ArrayDisplay(\$aArray1) ;_ArrayDelete(\$aArray1 , \$i) ;exitloop EndIf Next Next _WD_Shutdown() Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') \$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["start-maximized","disable-infobars"]}}}}' EndFunc ;==>SetupChrome Would appreciate if anyone can provide tips, or point me in the right direction in doing it.

test.xlsx
• By goku200
I'm having some issues with writing to column C when an element is found. It works on C2 but it does not continue to C3, C4, C5, etc..... I'm wanting to write "test" if the element //input[@id='username'] is found  \$someUser = _WD_FindElement(\$sSession, \$_WD_LOCATOR_ByXPath, "//input[@id='username']"). I have attached my HTML and Excel file along with my AutoIt code below:
#Include "wd_core.au3" #Include "wd_helper.au3" #Include "wd_core.au3" #Include "File.au3" #Include "Array.au3" #Include "Excel.au3" Local \$sDesiredCapabilities, \$sSession _WD_Startup() \$Ssession = _WD_CreateSession(\$sDesiredCapabilities) _WD_Navigate(\$sSession, "https://127.0.0.1/test.html") _WD_LoadWait(\$sSession) Local \$oExcel = _Excel_Open() Local \$oWorkbook = _Excel_BookOpen(\$oExcel, "C:\Users\<Username>\Downloads\test.xlsx") Local \$aArrayTest1 = _Excel_RangeRead(\$oWorkbook, 1, \$oWorkbook.ActiveSheet.Usedrange.Columns("A:A")) Local \$aArrayTest2 = _Excel_RangeRead(\$oWorkbook, 1, \$oWorkbook.ActiveSheet.Usedrange.Columns("B:B")) For \$i = 0 To UBound(\$aArrayTest1) - 1 _WD_Navigate(\$Ssession, \$aArrayTest1[\$i]) _WD_LoadWait(\$sSession) \$someUser = _WD_FindElement(\$sSession, \$_WD_LOCATOR_ByXPath, "//input[@id='username']") _WD_SetElementValue(\$sSession, \$someUser, \$aArrayTest2[\$i]) Local \$sElement = _WD_FindElement(\$sSession, \$_WD_LOCATOR_ByXPath, "//input[@type='submit'][@value='Submit']") _WD_ElementAction(\$sSession, \$sElement, 'click') _WD_LoadWait(\$sSession) Sleep(5000) If \$someUser Then Local \$aArray2D[2] = ["test"] _Excel_RangeWrite(\$oWorkbook, \$oWorkbook.ActiveSheet, \$aArray2D, "C2") EndIf Next Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') \$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["start-maximized","disable-infobars"]}}}}' EndFunc ;==>SetupChrome
test.html test.xlsx
• By roeselpi
hello again,
it has been a long time since i have been here and a long time since i last used autoit. ever so often when the time allows me to, then i follow up on an idea that i had a long time ago. i have done all the work on paper but now it is up to writing it in autoit and i keep stumbling over many little issues here and there. sometimes after a few days i will try again and get a step further but sometimes it just will not help no matter how long i try and think about a solution. for most of you it will be the basics but for me it is not all that easy, but at least i give it a try.
here is my code:
#include <MsgBoxConstants.au3> #include <StringConstants.au3> #include <Array.au3> #include <String.au3> ; ; PART 1: define replacements and check with msgbox ; Global \$y, \$z \$y = "Yes" \$z = "No" MsgBox(0,"replacements", \$y & @CRLF & \$z) ;the replacements in a message box ; ; PART 2: set the texts and check via console and msgbox ; Global \$my1string = "abab" ;the first specified text MsgBox(0,"my1string", \$my1string) ;the message box to output the first specified text Global \$my2string = "icic" ;the second specified text MsgBox(0,"my2string", \$my2string) ;the message box to output the second specified text ; ; PART 3: transform the strings to individual arrays ; \$my1array = StringSplit(\$my1string, "") \$my1array[0] = "" _ArrayDelete(\$my1array, 0) _ArrayDisplay(\$my1array, "my1array") ;the display of the first specified array \$my2array = StringSplit(\$my2string, "") \$my2array[0] = "" _ArrayDelete(\$my2array, 0) _ArrayDisplay(\$my2array, "my2array") ;the display of the first specified array ; ; PART 4: create an empty array for filling ; Global \$OutputArray[4] \$OutputArray[0] = "" _ArrayDisplay(\$OutputArray, "OutputArray") ;the display of the first specified array ; ; PART 5: compare & fill empty OutputArray with data after evaluation ; Global \$i, \$j, \$k For \$i = 0 to UBound(\$my1array) -1 For \$j = 0 to UBound(\$my2array) -1 For \$k = 0 to UBound(\$OutputArray) -1 If \$my1array[\$i] = "a" And \$my2array[\$j] = "i" Then \$OutputArray[\$k] = \$y Else \$OutputArray[\$k] = \$z EndIf Next Next Next _ArrayDisplay(\$OutputArray, "OutputArray") ;the display of the Newly filled Array In "Part 2" i make a string that is converted to an array in "Part 3" ... Now, I know that "a" and "i" are always in the exact same spot in both arrays and so i wanted to compare this and make a further array to document my findings by saying "yes" or "no" ... however my new array keeps saying just "no" allthough i can clearly see and know that it should say:
yes no yes no my guess is that there is something wrong within my for-loops and that the counting is somehow "off" i guess that when the first for-loop is finished it reaches the second whilst the second for-loop is checking the first which would explain why it always says "no" instead of seeing the obvious.
so my question would be: what is wrong with my for-loop? or where am i making an error that ultimately gives me the wrong results?
help is much appreciated.
kind regards
roeselpi

PS: sorry for my not so great english spelling ... stupid german sitting here trying out intermediate english skills.
×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...