It's probably because you use the ARRAY COUNT() command in a FOR/NEXT loop that uses ARRAY DELETE ELEMENT that makes ARRAY COUNT() less as it progresses. To fix it you just need to make a variable that stores the ARRAY COUNT().
Rem Project: ArrayListTest
Rem Created: Monday, November 07, 2011
Rem ***** Main Source File *****
sync on
SYNC RATE 60
BACKDROP ON
COLOR BACKDROP 0
global dim a()
for x=0 to 20
ARRAY INSERT AT BOTTOM a()
a()=x
NEXT x
pressed =0
do
for x=0 to ARRAY COUNT (a())
text 10,x*20,"Item=" +str$(a(x))
NEXT x
if spacekey()=1 and pressed =0
ARRAY INDEX TO top a()
` Make MaxRecords the array count
MaxRecords=array count(a())
` Go through all elements in the array
for y=0 to MaxRecords
if a() =y
ARRAY DELETE ELEMENT (a())
else
NEXT ARRAY INDEX a()
endif
NEXT y
endif
text 300,0,"Array count=" +str$(ARRAY COUNT (a()))
sync
LOOP
end
Also it's best to use code snips so any indenting is carried over to make it easier to read.
Code snips are like this:
[ code ]
Your code here.
[ /code ]
Remove the spaces between the brackets and we see this: