A function is provided that gives you the number of the last field on the form, i_maxnum():
int i_maxnum(fmp) FORMPTR fmp; /* Menu form to test */