Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

No. bytes limitation using FGETS 1

Status
Not open for further replies.

konLao

Programmer
Mar 10, 2003
61
US
I open file with a low-level function. If the size of the file is greater than 8,192 bytes, I will get "Function argument value, type or count is invalid" error message. I did some experiment and found: 8,192 bytes is OK; 8,193 bytes is NOT OK. Here's my code...

STORE FOPEN(lcLetter) TO gnFileHandle && <<<-- I HAVE 10,146 BYTES
STORE FSEEK(gnFileHandle, 0, 2) TO gnEnd
STORE FSEEK(gnFileHandle, 0) TO gnTop
do while !FEOF(gnFileHandle)
gcString = FGETS(gnFileHandle, gnEnd) && <<<-- THIS IS THE LINE THAT GENERATES ERROR.

Can anyone explain why or help?

Thank you,

Sam
 
This limitation is documented in the help file. It specifically says:

FGETS( ) returns a maximum of 8192 bytes. If you omit nBytes, FGETS( )returns 254 bytes by default.




-BP (Barbara Peisch)
 
Thank you for replying Barbara. I'm using MSDN98. It only specifies:

If you omit nBytes, FGETS( ) returns a maximum of 254 bytes by default.

I guess I'm learning something new here. My company will not spend more $ to upgrade the development SW.

I'm still open for suggestion about going around this problem since my file has more than 8,192 bytes.

sam
 
You can just break it up into chunks and do multiple FGETS. Since it leaves the record pointer where it left off, you don't even have to figure out where to start. This is from the VFP 6 help:

Data is returned starting from the current file's pointer position and continuing until a carriage return is encountered. The file pointer is then positioned on the byte immediately following the carriage return. The carriage return isn't returned as part of the string, and line feeds are discarded.



-BP (Barbara Peisch)
 
Barbara,

Good point. Why didn't I think of that. Thank you

Have a good day,

sam
 
konlao

It appears you are reading a text file. The FILETOSTR() function is usually preferred in this instance. The size of the character string FILETOSTR( ) returns can be very large. The amount of available memory or disk space determines if you can store the character string to a memory variable, array element, or memo field.

FGETS() is has advantages reading non-text files or communications port, but otherwise you may try the new VFP function FILETOSTR()


Jim Osieczonek
Delta Business Group, LLC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top