Advertisement

10.17.2007 at 11:01AM PDT, ID: 22899774
[x]
Attachment Details

Changing text file

Asked by wcsoctu in FoxPro Database

Tags: , , ,

Using FoxPro 9, SP2.  I have a function that simply adds desired text to a log file with a date and time stamp precedding the text.  Before adding, it checks to see if that particular string of text already exist.  If it does, it replaces the date and time stamp with the current date and time.  If it does not, it adds to the end of the file.  From the command line, I get the results expected.  I have SRVANY running on a Windows 2003 server.  It calls an exe that has a timer that when fired, calls a second exe.  This code is in the second exe.  However, when run from the server, the log entries are always added to the end of the log file, not replaced as expected.  Since it works perfectly from the command window, I am clueless where to start.  

FUNCTION SetLog
PARAMETER TextToAdd
* add text to log file with date/time stamp if the text does not exist,  if it does, replace that line
IF FILE('MyLog.txt')
      FileContents=FILETOSTR('MyLog.txt')
      NewFile=''
      LineAdded=.F.
      FOR MyCount=1 TO MEMLINES(FileContents)
            TheLine=MLINE(FileContents,MyCount)
            TheText=SUBSTR(MLINE(FileContents,MyCount),24)
            IF UPPER(ALLT(TheText))==UPPER(ALLT(TextToAdd))
                  NewLine=TRANSFORM(DATETIME())+' '+ALLT(TextToAdd)
                  LineAdded=.T.
            ELSE
                  NewLine=TheLine
            ENDIF
            NewFile=NewFile+IIF(EMPTY(NewFile),'',CHR(13)+CHR(10))+NewLine
      NEXT
      IF !LineAdded
            NewFile=NewFile+IIF(EMPTY(NewFile),'',CHR(13)+CHR(10))+ ;
                  TRANSFORM(DATETIME())+' '+ALLT(TextToAdd)
      ENDIF      
ELSE
      NewFile=TRANSFORM(DATETIME())+' '+ALLT(TextToAdd)
ENDIF

SET SAFETY OFF
STRTOFILE(NewFile,'MyLog.txt')
SET SAFETY ONStart Free Trial
[+][-]10.17.2007 at 11:11AM PDT, ID: 20095649

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: FoxPro Database
Tags: text, file, changing, filetostr
Sign Up Now!
Solution Provided By: wcsoctu
Participating Experts: 2
Solution Grade: B
 
 
[+][-]10.17.2007 at 11:23AM PDT, ID: 20095736

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.17.2007 at 11:25AM PDT, ID: 20095754

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.17.2007 at 11:32AM PDT, ID: 20095812

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.17.2007 at 11:33AM PDT, ID: 20095819

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.17.2007 at 07:09PM PDT, ID: 20098399

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]10.17.2007 at 07:10PM PDT, ID: 20098404

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_1_20070628