TRY USE (m.lcTable) IN 0 ALIAS thisDbf USE IN SELECT("thisDbf") CATCH TO loError ? "Table " + m.lcTable + " is bad." lnBadCount = m.lnBadCount + 1 FINALLY *Grabs NEXT DBF lcTable = SYS(2000,"*.DBF",1) ENDTRYbut during tracing, the code would stop on the finally and then get the next filename. By not using finally, I saved a click.
* Loop through current folder to find bad dbf >>* files by trying to open each. Log failures. >>CLEAR >>LOCAL lnBadCount, lcTable, loError >>lnBadCount = 0 >>*Grabs first DBF >>lcTable = SYS(2000,"*.DBF") >>DO WHILE NOT m.lcTable == "" >> TRY >> USE (m.lcTable) IN 0 ALIAS thisDbf >> USE IN SELECT("thisDbf") >> CATCH TO loError >> ? "Table " + m.lcTable + " is bad." >> lnBadCount = m.lnBadCount + 1 >> ENDTRY >> *Grabs NEXT DBF >> lcTable = SYS(2000,"*.DBF",1) >>ENDDO >>* Tell the user how it went >>? IIF(m.lnBadCount = 0, "No errors.", TRANSFORM(m.lnBadCount) + " table(s) could not be opened.")>>
>>>PUBLIC nCount, gnDbcnumber, gaDatabase[1], gnBadCount >>> >>>* Redirect our error handler to display relevant information >>>ON ERROR DO flagError WITH gaDatabase[nCount, 1] >>> >>>* Get directory of all DBF files >>>gnDbcnumber = ADIR(gaDatabase, '*.DBF') >>> >>>* Loop for number of tables to find bad ones >>>gnBadCount = 0 >>>FOR nCount = 1 TO gnDbcnumber >>> * Try to open it >>> USE (gaDatabase[nCount, 1]) IN 0 ALIAS thisDbf >>> >>> * If it opened, close it >>> IF USED("thisDbf") >>> USE IN thisDbf >>> ENDIF >>>NEXT >>> >>>* Restore our error handler >>>ON ERROR >>> >>>* Tell the user how it went >>>? IIF(gnBadCount = 0, "No errors", TRANSFORM(gnBadCount) + " tables could not be opened") >>> >>> >>>FUNCTION flagError >>>LPARAMETERS pcTable >>> * Note: you could add additional passed parameters to verify the error message, etc. >>> ? "Table " + pcTable + " is bad" >>> gnBadCount = gnBadCount + 1 >>>