If you take the for each out of the sub event and just have it as a separate event
so it becomes something like
start of layout....(set up as before)
(separate event)
if variable1=0
for each array -- set variable1 to variable1+1
do you get the right answer ?
(not checked)