ArrayCount

Hints, tips and tricks for newbies

Moderators: JRL, Dorian (MJT support)

Post Reply
nodochau
Pro Scripter
Posts: 135
Joined: Wed Jan 16, 2019 12:59 pm

ArrayCount

Post by nodochau » Thu Sep 10, 2020 5:59 pm

Hello All,
I have some array and I want to know the number of items in each array.
array1, array2....array20
If I use the code below:
let>k=0
Repeat>k
Add>k,1
ArrayCount>array%k%,itemCount
mdl>itemCount
Until>k=20
The program is crashed.
Please help!

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1415
Joined: Sun Nov 03, 2002 3:19 am

Re: ArrayCount

Post by Dorian (MJT support) » Thu Sep 10, 2020 6:59 pm

If I run your code without any arrays, I just get MDL returning zero 20 times.

However, if I use ArrayDim to create 20 arrays, mine hangs on ArrayCount too. In fact it hangs even if I simply create 1 array, and use ArrayCount in conjunction with a variable.

This hangs :

Code: Select all

ArrayCount>Array%k%,itemCount
This doesn't

Code: Select all

ArrayCount>Array1,itemCount
I haven't managed to figure out why yet. I will consult Marcus.

In the meantime, for anyone watching, this is the code I used to test :

Code: Select all

//Create the arrays
let>z=0
Repeat>z
Add>z,1
ArrayDim>array%z%,3
Let>array%z%_1=Fred
Let>array%z%_2=Sally
Let>array%z%_3=John
Until>z=5

let>k=0
Repeat>k
Add>k,1
//Warning - hangs
//ArrayCount>Array%k%,itemCount
ArrayCount>Array1,itemCount
mdl>itemCount
Until>k=5

nodochau
Pro Scripter
Posts: 135
Joined: Wed Jan 16, 2019 12:59 pm

Re: ArrayCount

Post by nodochau » Fri Sep 11, 2020 11:32 am

Yes, I have done the test as you did.
ArrayCount>array1, count: works but ArrayCount>array%k% will cause the program runs forever...

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1415
Joined: Sun Nov 03, 2002 3:19 am

Re: ArrayCount

Post by Dorian (MJT support) » Fri Sep 11, 2020 11:48 am

I have made Marcus aware of our findings and of this thread, and we'll see what he comes up with.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts