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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing to text file

Status
Not open for further replies.

spuppett

Programmer
Jan 25, 2003
48
US
I am having a heck of a time with this. I am not a foxPro programmer by any stretch of the imagination, but I have a task to accoplish. I need to write some text from a table to a file. I am working with some legecy code that uses fcreate and the like, but no matter what I do the handle that comes back is always = -1. the ferror I get is a 5, which I believe means that there is a permission issue. The file is NOT read-only.

Here is the code that I have
Code:
  IF FILE(chkFile)
    handle = FOPEN(chkFile)
  ELSE
    handle = FCREATE(chkFile)
  ENDIF
then the error checking which is select case on FERROR().

This code has worked on in the pass and I changed nothing in this section before I tried testing out the program.

Is there another way to do this, or does anyone have any suggestions on what I can do about the file handle being -1?
 
Is your filename a variable rather than a character expression?

Change your code to this with the character delimiters '' added

IF FILE('chkFile')
handle = FOPEN('chkFile')
ELSE
handle = FCREATE('chkFile')
ENDIF

 
Thanks for the response. I don't know what happened but all of a sudden it started working. I deleted the file this time and it worked. I tried that before but id didn't create it, but this time it did.

Thanks again.
 
Note that you are limited to the DOS 8.3 file (and path) naming standard in FPD & FPW, no matter what OS you are running under.

Rick
 
Also note, especially during testing, that once you handle = FOPEN() or handle = FCREATE() a file, that file is open and must be closed with an FCLOSE(handle), CLOSE ALL or even QUIT before you can open it again.


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top