Hellouser Posted November 30, 2009 Share Posted November 30, 2009 Hi All How to get the maximum index value of an array in autoit. ? Link to comment Share on other sites More sharing options...
KaFu Posted November 30, 2009 Share Posted November 30, 2009 Look at the function ubound() OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Hellouser Posted November 30, 2009 Author Share Posted November 30, 2009 Thanks KuFu for the reply. I am having a 2 diamentional array .When i tried the below code i am getting the ubound value as 5 instead of 45. Can u guide me how to correct it. #include <Array.au3> Local $avArray[90][5] For $i =0 to 45 For $j =0 to 4 $avArray[$i][$j] = $i Next Next _ArrayDisplay($aiResult, UBound($avArray,2)) Link to comment Share on other sites More sharing options...
jvanegmond Posted November 30, 2009 Share Posted November 30, 2009 Thanks KuFu for the reply. I am having a 2 diamentional array .When i tried the below code i am getting the ubound value as 5 instead of 45. Can u guide me how to correct it. #include <Array.au3> Local $avArray[90][5] For $i =0 to 45 For $j =0 to 4 $avArray[$i][$j] = $i Next Next _ArrayDisplay($aiResult, UBound($avArray,2)) Local $avArray[90][5] Ubound($avArray,0) = 2 Ubound($avArray,1) = 90 Ubound($avArray,2) = 5 github.com/jvanegmond Link to comment Share on other sites More sharing options...
Juvigy Posted November 30, 2009 Share Posted November 30, 2009 Change _ArrayDisplay($avArray, UBound($avArray,2)) to _ArrayDisplay($avArray, UBound($avArray,1)) And it will show you 90 as you have created the array with 90 elements , no matter only 45 are filled with data. Link to comment Share on other sites More sharing options...
KaFu Posted November 30, 2009 Share Posted November 30, 2009 (edited) Here ya go... #include <array.au3> Local $avArray[90][5] For $i = 0 To 45 For $j = 0 To 4 $avArray[$i][$j] = $i Next Next MsgBox(0,"",UBound($avArray,1) & @crlf & UBound($avArray,2)) _ArrayDisplay($avArray,"ArrayDisplay()",UBound($avArray,1)-20) ; -20 as an example only Edited November 30, 2009 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Hellouser Posted November 30, 2009 Author Share Posted November 30, 2009 Thanks Everybody for the reply. Here my intention is to get the maximum index value of the array(ie 45 as per the above program).Not the actual size of the array.The above array is filled with 45 values , i want to get the result as 45.How can it be possible. ? Thanks. Link to comment Share on other sites More sharing options...
KaFu Posted November 30, 2009 Share Posted November 30, 2009 (edited) Only by enumarating the array... presumes of course that there are no more values after the first empty was found... #include <array.au3> Local $avArray[90][5] For $i = 0 To 45 For $j = 0 To 4 $avArray[$i][$j] = $i Next Next MsgBox(0,"",UBound($avArray,0) & @crlf & UBound($avArray,1) & @crlf & UBound($avArray,2)) _ArrayDisplay($avArray,"Display max array-rows -20",UBound($avArray,1)-20) ; -20 as an example only for $i = 0 to UBound($avArray)-1 if stringlen($avArray[$i][0]) = 0 then $first_empty = $i MsgBox(0,"","First empty value: " & $first_empty) ExitLoop EndIf Next _ArrayDisplay($avArray,"Display only array rows until first empty value found",$first_empty-1) _ArraySort($avArray,1) ReDim $avArray[$first_empty][UBound($avArray,2)] _ArraySort($avArray,0) _ArrayDisplay($avArray,"Display whole array after ReDim") Edit: Maybe a sort and ReDim would be the best solution... updated example. Edited November 30, 2009 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Juvigy Posted November 30, 2009 Share Posted November 30, 2009 It is possible by creating small size array - [1][1] and then dynamically increasing the size of the array using the "Redim" in the loops For example : Local $avArray[1][1] For $i = 0 To 45 For $j = 0 To 4 Redim $avArray[$i+1][$j+1] $avArray[$i][$j] = $i Next Next MsgBox(0,"",UBound($avArray,1)-1 & @crlf & UBound($avArray,2)-1) exit Link to comment Share on other sites More sharing options...
KaFu Posted November 30, 2009 Share Posted November 30, 2009 Aehhmmmm, okay, the first sort should be before the enmuaration... #include <array.au3> Local $avArray[90][5] For $i = 0 To 45 For $j = 0 To 4 $avArray[$i][$j] = $i Next Next _ArraySort($avArray,1) for $i = 0 to UBound($avArray)-1 if stringlen($avArray[$i][0]) = 0 then $first_empty = $i ExitLoop EndIf Next ReDim $avArray[$first_empty][UBound($avArray,2)] _ArraySort($avArray,0) MsgBox(0,"",UBound($avArray,0) & @crlf & UBound($avArray,1) & @crlf & UBound($avArray,2)) _ArrayDisplay($avArray,"Display whole array after ReDim") OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
KaFu Posted November 30, 2009 Share Posted November 30, 2009 It is possible by creating small size array - [1][1] and then dynamically increasing the size of the array using the "Redim" in the loops That's true, but rediming every instances makes the process sloooow. I use something like this all the time, always add a buffer of 100 (or larger) on redim and after the loopp cut it down to the right size again: ; ReDim every instance Local $avArray[1][1] $timer = TimerInit() For $i = 0 To 1000 For $j = 0 To 4 Redim $avArray[$i+1][$j+1] $avArray[$i][$j] = $i Next Next MsgBox(0,"","Created" & @crlf & UBound($avArray,1)-1 & @crlf & UBound($avArray,2)-1 & @crlf & "in " & TimerDiff($timer) & " ms") ; ReDim every 100's instance ReDim $avArray[1][1] $timer = TimerInit() For $i = 1 To 1000 $avArray[0][0] = $i if UBound($avArray) = $avArray[0][0] then ReDim $avArray[UBound($avArray)+100][5] For $j = 0 To 4 $avArray[$i][$j] = $i Next Next ReDim $avArray[$i][5] MsgBox(0,"","Created" & @crlf & UBound($avArray,1)-1 & @crlf & UBound($avArray,2)-1 & @crlf & "in " & TimerDiff($timer) & " ms") OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Juvigy Posted November 30, 2009 Share Posted November 30, 2009 Agreed , This is quite faster... Local $avArray[1000][1000] For $i = 0 To 427 For $j = 0 To 678 $avArray[$i][$j] = $i Next Next Redim $avArray[$i][$j] MsgBox(0,"",UBound($avArray,1)-1 & @crlf & UBound($avArray,2)-1) exit Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now