need help as iam newbee this programe is hanging on the middlle some times runs

its ok but the program is sturckup when relays picks connected to o/p,i had done maximum changes but result is nil at last posting in forum