Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Corrupted dbf names in txt file
Message
From
11/01/2007 08:14:01
 
 
To
11/01/2007 08:04:38
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows XP
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01184495
Message ID:
01184499
Views:
16
>I use following procedure to findount corrupt tables in a dbc,
>Then store the name of all corrupt dbf's in ("c:\Baddbf.txt").
>Then proble is:
>If more than one dbf is corrupted then only last dbf name is stored into txt file.
>
>Please modify codes, how to store the name of all dbf's into given txt file.
>
>Please help.
>
>parameters mdbcname
>mdbcname=(sys(5)+alltrim(sys(2003)))+'\TABLES\ACWS.dbc'
>
>if empty(mdbcname)
>	return
>endif
>
>close all
>close data
>
>open database (mdbcname) excl
>= adbobjects(latablearray, "TABLE")
>
>for i=1 to alen(latablearray) && loop through each table in the array
>	mtablename=latablearray(i)   && pick up table name from array
>	=opentable(mtablename) && attempt to open table
>next x
>
>procedure opentable
>parameters M.table
>
>x=0
>on error x=error()
>use (M.table) in 0
>on error
>
>if x<>0 && Possible table corruption
>	local lnhandle,ix
>	lnhandle = fcreate("c:\Baddbf.txt")
>	do case
>	case "corrupt"$message()
>		=fputs(m.lnhandle,"Table "+m.table+" is corrupt!",48,"Unable to open table")
>	case "does not exist"$message()
>		=fputs(m.lnhandle,"Table "+m.table+" does not exist",48,"Unable to open table")
>	case x=1705 or "cannot access"$message()
>		=fputs(m.lnhandle,"Table "+m.table+" does not exist",48,"Unable to open table")
>	otherwise
>		=fputs(m.lnhandle,"Table "+m.table+": "+message()+"!",48,"Unable to open table")
>	endcase
>	=fclose(m.lnhandle)
>endif
>



Don't use FCREATE() unless the file is new (i.e. does not yet exist)
IF NOT FILE("c:\Baddbf.txt")
  lnhandle = fcreate("c:\Baddbf.txt")
ENDIF
Use FOPEN() for R/W (see help for parameters)

You could use FWRITE() instead of FPUTS(), or you could append to a text file with strtofile() as Borislav suggested. A matter of choice.

The top section:
if empty(mdbcname)
   return
endif
Is meaningless as it will never run because you are setting the DBC name on top

I would use TRY..CATCH instead of ON ERROR and would also add TRY..CATCH to the line when you try to open the DBC.


Alex Feldstein, MCP, Microsoft MVP
VFP Tips: English - Spanish
Website - Blog - Photo Gallery


"Once again, we come to the Holiday Season, a deeply religious time that each of us observes, in his own way, by going to the mall of his choice." -- Dave Barry
Previous
Reply
Map
View

Click here to load this message in the networking platform