And mstrcmtr, if you use some older version of VFP, 7 or below, you don't have TRY CATCH, but you have ON ERROR * or this way:
Code:
LOCAL llError
ON ERROR llError = .T.
* Try
* one line of code
If llError
* catch block
Endif
llError = .F. && endtry
* next try block...
What you can't do in that structure is let the first error jump to the If llError catch block. If the Try block has several lines of code and one line errors, that just set llError=.T. and the next line still is executed, the only way to have the same behaviour as with TRY CATCH is controlling llError after each line or only have one line of code. Therefore I made the comment "* one line of code". That part up to IF llError can have multiple lines of code, too, if you're sure they work out.
Try Catch can be extended to give you an Exception object telling line of error, error number and message, etc, so you can better react to the specific error happening in the try block.
In this case I used three try catch blcoks, because errors happening in each of the three steps have very different implications. You can't do anything like removing a tag or field without exclusive access, therefore the first catch block is returning, you can simply ignore not finding the index tag named the same as the fieldname in the second block, so there just is the comment in that catch block, but you have to know what to address if you still can't drop a column though a simple index tag is not existing. I can only display SYS(2018) knowing the error comes from the ALTER TABLE.
And in the end, even if that code succeeds you'll see how failsafe your assumption was about the field not being used. You don't have to ask your customers about the field, you have to look into any code. I am not listening to single end users saying they don't need some feature, I'm not listening to the customers company stake holder confirming that this field or feature is obsolete, because next day, week, month some other user missed that field/feature. It happened far too many times and people don't learn the lesson from it.
Last not least, even if you don't want to go the TRY route, Mike posted early on, how to know a tag with field name exists: [tt]llTagExists = (TAGNO("SomeField") > 0)[/tt]. If you go by that convention, that'll be sufficient and you should at least know that, if you don't know how your own tables are structured.
Bye, Olaf.