the following line of code on execution gives an error -I have no idea why this would happen. This is just a local declaration. Try changing it to this:
LOCAL loAddressBook, loContact, lnContactCount
IF .Class = loContactIt should be
olContact as #DEFINEd below - not loContact.
#define olContact 40