The ulock command locks or unlocks a file specified by a file variable.
ULOCK FileHandle LOCK|UNLOCK FOR n THEN statement(s) ELSE statement(s)
FileHandle must be opened for WRITE or READWRITE. The number of contiguous bytes from the current file pointer position to be locked or unlocked is indicated by n. If an error occurs, the ELSE path is executed. If n is -1, all bytes from the present position of the file pointer to the end of the file are locked. This statement does not move the file pointer. n has a maximum lockable region size of 4 MB.
The ulock command may be used against a file opened in READ mode. The ulseek() function allows the file pointer to be positioned beyond the locked section of the file.
The following statements open a file, and then lock the first 50 bytes of that file. Data is then written into the locked section of the file. The uwrite command advances the file pointer for the file (in this case, by 17, the length of the string). The ulseek function is used to move the file pointer back to the beginning of the file so that the first 50 bytes may be unlocked.
FILENAME="c:\books\chap2.txt" UOPEN FILENAME FOR WRITE TO FILEDES ELSE PRINT "Unable to open ":FILENAME STOP END * Pointer by default, set to begining of file ULOCK FILEDES LOCK FOR 50 ELSE PRINT "Unable to Lock first 50 bytes of ":FILENAME GOTO EOJ: END UWRITE "THIS IS TEST DATA" ON FILEDES THEN * NOTE: UWRITE will advance Pointer END ELSE PRINT "Unable to write to ":FILENAME GOTO EOJ: END * Set pointer back to begining of file IF (ULSEEK(FILEDES,0,0) = -1) THEN PRINT "ULSEEK failed" GOTO EOJ: END ULOCK FILEDES UNLOCK FOR 50 ELSE NULL * EOJ: UCLOSE FILEDES ELSE NULL