** o.CreateInvoice() LParameters tnCustId ** make sure customer exists Select custid ; From customer ; where custid=tnCustId ; Into Cursor cutmp If RecCount()=0 MessageBox("Customer Id not found.", 16, _Screen.Caption) Do CleanUp() Return .F. EndIf ** make sure they have no outstanding money owed Select Sum(money_owed) as money_owed ; From invoices ; Where custid=tnCustId ; Into Cursor cutmp If RecCount()>0 MessageBox("Customer owes " + Transform($1*cutmp.money_owed), 16, _Screen.Caption) Do CleanUp() Return .F. EndIf ** several other such processes go here ** ** actual meat of the code goes here **This I would refactor into different methods, each of which handle cleanup and error messaging pertinent to themselves only - and therefore may be reused by other processes. And by doing this, you can also get around all the
IF !llRetVal
checks with a case statement.** o.CreateInvoice() LParameters tnCustId Local llRetVal Do Case Case !this.CustomerExists(tnCustId) Case !this.CustomerOwesMoney(tnCustId) Case !this.CustomerOverLimit(tnCustId) ** etc. Otherwise ** this ~Ex() method now contains the meat of the code, ** also refactored if necessary llRetVal=this.CreateInvoiceEx(tnCustId) EndCase Return llRetVal
... >do Cleanup >Return .F. >ENDIF>
...
>llReturn = .F.
>ENDIF
followed by EXTRA code that has to check llReturn every time something new was to be done.