NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

How to get number of rows and columns in a two dimensional array ?

Hello,
What would be the simplest way to get number of rows and columns in a two dimensional array represented as integers ?
I'm looking for another solution as For...Each loop in case of large arrays.
Regards,
Petri
 
 
 
0 Kudos
Message 1 of 9
(5,965 Views)
Hi,
 
Use GetArrayBounds( array, lower_bounds, upper_bounds)
 
If your array is 9x2 [0..8][0..1] then the lower_bounds would be "[0][0]" and the upper bounds would be "[8][1]".
 
Then you would need to strip off the square brackets.
 
Hope this helps
Regards
Ray Farmer
Regards
Ray Farmer
0 Kudos
Message 2 of 9
(5,964 Views)

Hello Ray,

That is my approach. Instead of using complicated string manipulations, is there a simple method to filter brackets in case size of array will be increased e.g. from [9][2] to [10][2] ? It would nice to have integrated functions in TestStand to do these things for arrays. 

Regards,

Petri 

0 Kudos
Message 3 of 9
(5,959 Views)

Hi Petri,

I can only think of SearchAndReplace.

If you do SearchAndReplace "][" to "," then change the "[" to "" and "]" to "" this will leave you a resultant string of "9,2".

If you then convert to number by Val(Str(resultant),"%f")) you will get a number of 9.2

Dont know if that will help you

Regards

Ray

Regards
Ray Farmer
0 Kudos
Message 4 of 9
(5,956 Views)

Hello Ray,

Thanks for your quick answers. Yes, that could be an approach, unfortunately there is no function to get integer and decimal from 9.2 float. Probably it could be easier to do the job in CVI or LV which I was thinking about to avoid.

By the way,  second parameter in Val() returns boolean according to 3.5. I'm not sure if "%f" could work or has any effect.  

Regards,

Petri

0 Kudos
Message 5 of 9
(5,953 Views)

Hi,

There is a Str() to format it to float before turning it to Val() eg..Val(Str(..)).

Yeah you still need to get the left and right side of the decimal point.

Or you can take the "9,2", wrap it with {} and use it to initials an empty array.

eg Locals.MyArray = Evaluate ( "{"+Locals.resultant + "}") where Locals.resultant = "9,2".

But you are right, probably easy to pop into labview.

 

Regards

Ray

Regards
Ray Farmer
0 Kudos
Message 6 of 9
(5,950 Views)
Hi Petri,
 
See a attached txt file for obtaining two arrays with upper and lower index values
 
Regards
Ray
Regards
Ray Farmer
0 Kudos
Message 7 of 9
(5,947 Views)
Hi Ray,
Thanks for the script. It gave me an idea, so I modified the script in order to clarify even arrays like e.g. [9][10] where the second bound ends to zero. Finally, it is a complex string manipulation. Attached a modified sequence.
Regards,
Petri
 
0 Kudos
Message 8 of 9
(5,904 Views)

That's OK, glad it was useful.

Regards

Ray

Regards
Ray Farmer
0 Kudos
Message 9 of 9
(5,900 Views)