If I may suggest, read this "sticky":
Read this before posting a programming question
If you had posted your code, and the error message, rather than excerpting with "all sorts of compile errors" then we might have been able to see the exact problem.