I have a method IsConsistent(tableName)Logical that has to return true or false to indicate the consistency of a table and if consistent perform some editing on it. The function needs to open the table by first as a TCursor. Usually I’ve used this trick that Jedstar showed me to run a switch with case not tc.open(tableName) : showError() return. The problem is that I can’t return false if the Tcursor can’t open or can’t get in edit mode because that is different from an inconsistent table. An inconsistent table needs different operations done on it that a non-opening table shouldn’t get. How should I handle the error of the table not opening to show that consistency checking was not done now?
Another Leo _ _ ___________________ _ _ We are Micro$oft You will be assimilated Resistance is futile
Well, if it was me, I would just return a string. The call would look something like this:
var retVal string endVar
retVal = isConsistant(tableName) switch case retVal = "System Error": ; take action case retVal = "Consistant": ; take action case retVal = "Inconsistant": ; take action endSwitch
Then your method with return a string instead of a logical. This also makes your code very easy to read.
I have moved to ALWAYS (well, almost) returning a logical.
And passing a parameter on the command line to handle this situation.
IsConsistent(tableName, stReturn) Logical
You can still return a logical True/False, then if False handle the stReturn.
if not isConsistent("myTable.db",stReturn) then switch case stReturn="I" : handleInconsistent() case stReturn="E" : handleError() endswitch endif
That way, if consistent no further action is taken; the switch only activates on a return of False.
Not a lot different than Cliff's methodology. I do it for consistency. But then much of my coding is for OTHERS who use my products; this makes it a little easier for them to know how to use my products - consistently. They can automatically code calls to my library methods as logical returns, and handle the last parameter as the exception/error/code.