Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VALIDATE command into a function
Message
From
10/02/1997 16:26:41
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
VALIDATE command into a function
Miscellaneous
Thread ID:
00019948
Message ID:
00019948
Views:
110
I include in this message a function that I wrote and thought that it could be useful to someone. Is the VALIDATE command made function.

In my application I had to make some maintenance routines to be used by non technical people. This is why I wanted to transform the VALIDATE command into a function that returns .t. or .f. This way I can prompt to the user whatever message and options I want, depending on the result of the function and thus I can hide the "complexities" of the data base world to the user.

The follwing is the function in the basic form. It can be adapted so as to generate message or whatever. The compFiles() function is not a VFP function; I don't include the function I used because is a binary compare function and is not the best one for this purposes. You can create your own text file compFiles() function or use an already written function.
*------------------------------------------------------------------
*-- Validates the given data base and returns .T. if it's OK.
*-- To do so it creates a dummy database to check for the message that
*-- is created when a DBC is validated with no errors. It then
*-- compares this message to that of the given data base.
FUNCTION validateDBC(cDBase)
#DEFINE OUTFILE "valdbc.txt"
#DEFINE OUTFILETMP "valdbc.tmp"
LOCAL lcTempDB, ;
      lcSafety
	  
lcSafety = set('safety')
SET SAFETY OFF

*The dummy database has to have the same name to generate the same message.
*SYS(2023) is the temporary directory.
lcTempDB = sys(2023) + '\' + cDBase
CREATE DATABASE (lcTempDB)
VALIDATE DATABASE TO FILE OUTFILETMP NOCONSOLE
CLOSE DATABASE
DELETE DATABASE (lcTempDB)

SET DATABASE TO (cDBase)
CLOSE TABLES

VALIDATE DATABASE TO FILE OUTFILE NOCONSOLE

llValid = compFiles(OUTFILE, OUTFILETMP)

SET SAFETY &lcSafety
DELETE FILE OUTFILE
DELETE FILE OUTFILETMP
RETURN llValid
Best regards,
Javier.
Next
Reply
Map
View

Click here to load this message in the networking platform