Logo

Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.

Sys(2007)

SYS(2007) returns a checksum that you can use to “fingerprint” a character string. This checksum can be used later to check if the value of the character string has changed. This function is the source of the CkVal field in the FoxPro resource file. Checksums are related to the original character field by some magical formula, which returns a number from zero to 65,535. Obviously, with only 65,536 combinations to choose from, SYS(2007) does not create a perfect, unique entry. For example, checksums run on the Details field of VFP 3’s FoxHelp.DBF yield 72 duplicates on fewer than 3,000 records. But as a flag to determine if a single field has changed, it’s suitable for many functions.

Usage

cReturn = SYS( 2007, cString )

Parameter

Value

Meaning

cString

Character

Value to be checksummed.

cReturn

Character

5 characters containing a left-justified number.

Example

cCkVal = SYS(2007,Foxuser.Data)

* * LogTime.PRG - time entry into resource diary
PARAMETERS tcLogMessage
PRIVATE ALL LIKE l*
IF EMPTY(SET('RESOURCE',1))
  WAIT WINDOW PROGRAM() + ": No resource in use!"
  RETURN .F.
ELSE
  lcResSet = SET('RESOURCE')
  SET RESOURCE OFF
ENDIF

lnSelect = SELECT()
SELECT 0
USE SET('RESOURCE',1) AGAIN ALIAS Diary
LOCATE FOR TYPE = "DATA" AND ;
           ID   = "DIARYDATA" AND ;
           NAME = DTOS(DATE())

IF NOT FOUND()
  INSERT INTO Diary VALUES ("DATA", "DIARYDATA", ;
                           DTOS(DATE()),.F., 0, TIME() + ;
                           " " + tcLogMessage, DATE())
ELSE
  REPLACE DATA WITH DATA + CHR(13) + TIME() + " " + tcLogMessage
ENDIF

REPLACE CkVal WITH VAL(SYS(2007, DATA))
USE IN Diary
SELECT (lnSelect)
SET RESOURCE &lcResSet
RETURN

The second example posts the message passed to the function as a calendar entry, appending to an existing entry or creating a new one. It uses SYS(2007) to update the CkVal field. (Hint: If you want to hide a calendar entry, just change its checksum.) If this code looks a little funny, it’s because it is essentially unchanged since (and still runs in) FoxPro 2.0, despite a few changes to the resource file’s structure.

See Also

Set Resource, Val()