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

Problem with add to text file

Status
Not open for further replies.

JBonczek

Programmer
Apr 7, 2004
9
CZ
Hi,

I have problem with logging into text file. When I run the program within design mode so it work well. But when I run it within runtime (app.exe) so it doesn't work. It cannot open the text file.
I use this function:

function logevent(cPozn)
local flog1
if file("log.txt")
flog1 = fopen("log.txt",12)
fseek(flog1,0,2)
else
flog1 = fcreate("log.txt")
endif
IF flog1 < 0
WAIT 'error' WINDOW NOWAIT
endif
cText = ttoc(datetime())+" "+cPozn
FFLUSH(flog1)
fclose(flog1)
endfunc

Thanks for any Ideas
 

Not sure, but I suspect this is a pathing problem. In your development environment, the text file is probably in the search path or the default directory. In the run time environment, your paths might be different.

To verify that, try hard-coding the full path with the filename. If that works, then that will confirm the problem.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
personally, i use STRTOFILE() in my event logger.. never had a problem with it and it's much easier than all that low-level file stuff.. of course, the user will need write-access to the program directory..

Code:
PROCEDURE genLog
   LPARAMETERS tcPassedMess
   LOCAL lcstr

   IF TYPE('tcPassedMess') # 'C' OR EMPTY(tcPassedMess)
      RETURN .f.
   ENDIF

   STORE 'Date/Time: '+TTOC(DATETIME())+CHR(13)+;
      ALLTRIM(tcPassedMess)+CHR(13) to lcstr

   lcstr = STRTRAN(lcstr,CHR(13),CHR(13)+CHR(10)+CHR(9))+;
      CHR(13)+CHR(10)

   STRTOFILE(lcstr,ALLTRIM(JUSTSTEM(SYS(16,0)))+".log",1)
	
   RETURN .t.
ENDPROC

HTH
-- frank~
 
I resolve the problem. Problem was that if this logfile is added into project so it desn´t works. When I remove the logfile form project so it works well.
 
JBonczek

Problem was that if this logfile is added into project so it desn´t works

That's because the log file was being bound into the EXE, and was therefore read-only, so FCREATE() didn't work.

You can still add the file to the project, if you exclude it from the build (right-click on filename and choose Exclude).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top