You're not doing it right, but you need not code it anyway - Zorro has already functions for all array statistics, MaxVal and MinVal in this case.