Are you sure it is not just that you are getting an error from one of those lines?

comment out the "on error" line, run it on some supposedly good data and tell us what like it errors on and what message.