Sign in to follow this  
Followers 0
NDog

How to return columns in a row using ubound?

6 posts in this topic

#1 ·  Posted (edited)

I am trying to get the number of coumns in each row. What is the technical name, elements in array?

Posted Image

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 by NDog

Share this post


Link to post
Share on other sites



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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 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.

Share this post


Link to post
Share on other sites

#6 ·  Posted (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 by NDog

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  
Followers 0