When posting code to the forum, I would also suggest you read these guidlines to correctly format the code.

When writing your code, I would also strongly suggest using a code editor if you are not already doing so -
Personally, I find that the Visual LISP IDE provided with AutoCAD is by far the most suitable for writing AutoLISP:

The Visual LISP Editor - Part 1
The Visual LISP Editor - Part 2
An Introduction to the Visual LISP IDE
Retrieving Information About a Function
A Shortcut to Localising Variables
Debugging Code with the Visual LISP IDE