The purpose of this Programming Forum is to help people solve problems. You post some code that doesn't work, we attempt to tell you what's wrong with your code.
[quote user="Tom"] Can someone please have a go at this?[/quote]
We're not here to write code for you. As Jan wrote: hire a developer.
Furthermore, it's not clear what 'this' is — there's no specification. Probably in your mind everything is clear, but from our point of view, all we know is that you want to automate cadastral labelling.