dmob Posted March 7, 2022 Share Posted March 7, 2022 I query the number of columns in array but getting unexpected result. In both cases in the code below, the array is created and displays properly, j but Ubound(array, 2) returns 0. I was expecting 1. Can anyone else confirm this on ver 3.3.16 or my expectation is wrong (again) ? #include <Array.au3> Local $aArray[4][4] For $i = 0 To 3 For $j = 0 To 3 $aArray[$i][$j] = $i & $j Next Next ;_ArrayDisplay($aArray, "Original") Local $aExtract = _ArrayExtract($aArray, -1, -1, 0, 0) _ArrayDisplay($aExtract, "$aExtract") ConsoleWrite("Colums1: " & UBound($aExtract, 2) & @CRLF) Local $aNew[4] For $i = 0 To 3 $aNew[$i] = $aArray[$i][0] Next _ArrayDisplay($aNew, "$aNew") ConsoleWrite("Colums2: " & UBound($aNew, 2) & @CRLF) >"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" /ErrorStdOut "C:\Users\DMOB\AppData\Local\Temp\Untitled 1.au3" Colums1: 0 Colums2: 0 >Exit code: 0 Time: 3.804 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 7, 2022 Moderators Share Posted March 7, 2022 dmob, Both of the arrays are 1D (look at the values displayed at the bottom of the ArrayDisplay dialog) so there are no "columns" And if you check @error after the UBound call, you will see it is non-zero, as the Help file tells you it will be for a failure. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
dmob Posted March 7, 2022 Author Share Posted March 7, 2022 (edited) I see. I have a function B that accepts a 1D or 2D array as parameter. This particular 1D array in the sample code is extracted from a 2D array from another function A. How would I check for the number of columns in function B? Edited March 7, 2022 by dmob Or would I need to check number of rows in array if Ubound returns error 2 to verify the input array in func B? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 7, 2022 Moderators Share Posted March 7, 2022 dmob, Just use UBound with the $UBOUND_COLUMNS parameter. A 2D array will give you a non-0 return - if the return is 0 then check @error and if it too is set then you have a 1D array. I have no idea about the "rows" question. Do you mean that you want to use 1D elements as if they were the col 0 elements of each column? If so, then _ArrayTranspose might be the function you need. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Solution dmob Posted March 7, 2022 Author Solution Share Posted March 7, 2022 51 minutes ago, Melba23 said: if the return is 0 then check @error and if it too is set then you have a 1D array I figured that was the only option. Kinda hard to wrap my head around, I thought a 1D array as in array[4] has 1 column, now I gotta learn it has 0 columns Link to comment Share on other sites More sharing options...
pixelsearch Posted March 7, 2022 Share Posted March 7, 2022 3 hours ago, dmob said: Ubound(array, 2) returns 0. I was expecting 1 Dmob, I understand you because it always frustrated me too. We see 1 column in both following cases, when creating an array with : Local $aArray[10] ; or Local $aArray[10][1] But in 1st case (the 1D case) number of cols = 0 And in 2nd case (the 2D case) number of cols = 1 @jpm simplified it when scripting the new ArrayDisplay, with this line : $_g_ArrayDisplay_nCols = ($_g_ArrayDisplay_iDims = 2) ? UBound($_g_ArrayDisplay_aArray, $UBOUND_COLUMNS) : 1 ; Jpm's 1D => 1 (new !) (comment at the end of line comes from my reworked version of ArrayDisplay) I think he did great, because it brought fresh air and simplified the whole function. dmob and Musashi 1 1 Link to comment Share on other sites More sharing options...
dmob Posted March 7, 2022 Author Share Posted March 7, 2022 1 minute ago, pixelsearch said: And in 2nd case (the 2D case) number of cols = 1 Thank you @pixelsearch, this clarifies it totally Link to comment Share on other sites More sharing options...
pixelsearch Posted March 7, 2022 Share Posted March 7, 2022 You're welcome, always a pleasure to chat with you. Link to comment Share on other sites More sharing options...
pixelsearch Posted March 7, 2022 Share Posted March 7, 2022 (edited) dmob : could you please have a look at the function Sortall() found in the last post of this link, just below the line : 2) Include file "SortAll.au3" It doesn't check on @error but it could help you with the order of the tests to do in your B function, the 1st step should always be : If Not IsArray($aArray) Then ... Hope it helps. Edit: yes, the sentence "always 0 for 1D array" will be found there, in a comment, since the 1st day when the function was posted. Always good to write things easily forgettable Edited March 7, 2022 by pixelsearch Link to comment Share on other sites More sharing options...
dmob Posted March 8, 2022 Author Share Posted March 8, 2022 @pixelsearch I did something along those lines following melba's input. Thank you much, I appreciate your assistance. 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