[ ]
Here is a function that I use to find a line in a low level text file.
******************************
*
* Find line containing search string
*
******************************
*
* Finds next occurance of qStr in existing open file designated by qHandle.
* Automatically increments file pointer to end of last line processed.
* Always begins at current file pointer position in file.
* Continues until carriage return found or maximum bytes searched.
*
* SYNTAX:
* = LLFindLine(qHandle, qStr[, qLine[, qBytes]])
*
* ENTRY:
* qHandle N: File handle of file to be examined
* qStr C: String to find
* qLine C: "l" if left portion of line wanted
* C: "r" if right portion of line wanted
* Defaults to line containing qStr
* qBytes N: Number of bytes to search from current file position
* Defaults to 762 bytes
*
* EXIT:
*
* RETURNs:
* '' = String not found
* string = Part of file wanted
*
******************************
PARAMETER qHandle, qStr, qLine, qBytes
PRIVATE ALL LIKE z*
zfound = 0
IF TYPE('qBytes') <> 'N'
qBytes = 762
ENDIF
z = ASC(FORMAT(qLine))
DO WHILE EMPTY(zfound)
zthisline = FGETS(qHandle, qBytes)
IF FEOF(qHandle) AND EMPTY(zthisline)
EXIT
ENDIF
zfound = AT(qStr, zthisline)
ENDDO
DO CASE
CASE EMPTY(zfound)
zfound = ''
CASE z = 82 && Right
zfound = SUBSTR(zthisline, zfound)
CASE z = 76 && Left
zfound = LEFT(zthisline, zfound - 1)
OTHERWISE
zfound = zthisline
ENDCASE
RETURN zfound
The line in red uses one of my handy dandy functions which is way to long to put here. So, you will need to change that line to something that sets z to the ASCII value of qLine. Be aware that in the default mode that qLine can be .F., so a simple ASC() will not work.
mmerlinn
"Political correctness is the BADGE of a COWARD!"