B4J Question B4J - Simple Question - Number of Objects

AlexOfOz

Active Member
Licensed User
Longtime User
I'm sure there must be a simple way to do this, but I haven't got a clue.

I have many buttons of the same type, that I am managing with an array. How can I determine how many buttons I have, so I can include that in my DO loops?

In other words, how do I find the missing number -

For i = 0 to ??? <---- missing number

Thanks.
 
Thank-you Erel, I will try FOR EACH instead.

The root of my question was answered with ARR.LENGTH. I expected there would be a way, just like the LENGTH parm for a string, but it never occurred to me that it could be so straight forward.

I am now using this method throughout my program and it is working beautifully.
 
Upvote 0
It is preferable when you don't need the index.
1. It is safer as you can't get the first or last index wrong:
Code: Copy
For i = 1 To Arr.Length 'both of them are wrong here
 Dim btn As B4XView = Arr(btn)
 ...
Next
2. It is shorter and more clear:
Code: Copy
For Each btn As B4XView In Arr

Next
 
Upvote 0
Back
Top