NDog Posted July 20, 2012 Share Posted July 20, 2012 (edited) I am trying to get the number of coumns in each row. What is the technical name, elements in array?ConsoleWrite("-"&@CRLF) ConsoleWrite(UBound($Office,0) &@CRLF) ConsoleWrite(UBound($Office,1) &@CRLF) ConsoleWrite(UBound($Office,2) &@CRLF) ConsoleWrite(UBound($Office,3) &@CRLF) ConsoleWrite("-"&@CRLF)It returns- 2 4 7 0 -But I want to see- null 4 6 6 -What did I do wrong? Edited July 20, 2012 by NDog Link to comment Share on other sites More sharing options...
water Posted July 20, 2012 Share Posted July 20, 2012 Please read the help file for "UBound" (again): "If this parameter is 0, the number of subscripts in the array is returned." All other values return the size of this dimension. You have a two dimensional array with 4 rows and 7 columns. The indices to access this elements (as the numbering starts with 0) go from 0 to 3 and 0 to 6. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
JohnOne Posted July 20, 2012 Share Posted July 20, 2012 You can think of an array in autoit3 as rectangular. If the row with the most columns is 7, then they all have 7 column, so ubound will only serve you as a tool here. You will need to iterate/loop through your array, and test in some manner whether the elements are empty or not. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
water Posted July 20, 2012 Share Posted July 20, 2012 You can think of an array in autoit3 as rectangular.A two dimensional array is a "rectangular", a three dimensional array is a "cube" etc.If the row with the most column is 7, then they all have 7 column...The number of rows and columns of an array is set by the Global statement defining the array and is what is returned by UBound regardless how many rows/columns you have put data into. To change the dimensions (rows/columns) of an array you have to use ReDim.There is a very good tutorial about arrays in the Wiki. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
jdelaney Posted July 20, 2012 Share Posted July 20, 2012 (edited) Need logic to count those that are filled: dim $somearray[2][5]=[[1,2,3,"",""],[9,8,7,6,""]] for $i = 0 To UBound ($somearray)-1 $counter = 0 For $j = 0 to UBound ( $somearray,2)-1 ;ConsoleWrite ( $somearray[$i][$j] & @CRLF) If stringlen ($somearray[$i][$j])>0 Then $counter=$counter+1 Next ConsoleWrite ( $counter & @CRLF ) Next Edited July 20, 2012 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
NDog Posted July 21, 2012 Author Share Posted July 21, 2012 (edited) Thank you all for your replies. I read them very carefully and now understand why they are returning such values. The Ubound,0 is the dimensions = 2 because it is 2D, 1 is the row, 2 is the columns.. I now know I should rephrase my original question as "How do I count the number of non empty columns in a [selected] row in an array" For example I have $Office[1][$i], where $i is unknown. First I should do a test for an empty value which is: "" Then loop through them So I guess it goes like this For $i =0 To UBound($Office,2) -1 ;cause 2 stands for columns (7), and minus 1 because it is actually 0 to 6 If $Office[1][$i] <> "" Then $count+1 EndIf Next ConsoleWrite($Office[1][$count]) Or something... Anyway thanks for the advice, its very good Edited July 21, 2012 by NDog 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