Split your problem up into smaller pieces, and concentrate on a single piece at a time. Post an SSCCE that demonstrates just that single piece, and we'll go from there.

Recommended reading: Arrays...