Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Ken Murphy
  Where is Ken Murphy?
 Springhill
 Canada
 Ken Murphy
 To: Binod Binani
  Where is Binod Binani?
 Kolkata
 India
 Binod Binani
 Tags
Subject: RE: Writing to text file
Thread ID: 104628 Message ID: 104751 # Views: 1 # Ratings: 0
Version: Visual FoxPro 8 Category: General VFP Topics
Date: Sunday, August 20, 2006 2:21:20 PM         
   


> > > > > Hi Experts,
> > > > >
> > > > > FPUTS Writes a character string, carriage return, and line feed to a file
> > > > > FWRITE does not.
> > > > >
> > > > > i need to write a character string to a file then using only line feed i must be able to write another to next line. is this possible?
> > > > >
> > > > >
> > > > > TIA
> > > > >
> > > > >
> > > > > .ian.pano.

> > > >
> > > > FWRITE(lnHndl,lcMyCharacterString+CHR(10))
> > > >
> > > > Ken
> > > > You shall know the truth - and the truth shall set you free. (John 8:33)

> > >
> > > oh my!!! LOL!!!!
> > >
> > > thanks!
> > >
> > > .ian.pano.

> >
> > Sometimes it is hard to see the forest - all those ^%$#@ trees get in the way! :)
> >
> > Ken
> >
> > You shall know the truth - and the truth shall set you free. (John 8:33)

>
>
>
> new to vfp
>
> Thanks Mr Ken
>
> But one doubt?
>
> FWRITE(lnHndl,lcMyCharacterString+CHR(10))
>
> will to work with myonetxt.txt while some one else is also using
> in another pc. (Multi-User)
>
> {myonetxt.txt is opened with notepad in another PC}
>
> When opening file using FOPEN and system hangs.
>
> I don't know what happend
>
> Please help.


When using low level commands like FOPEN(), FWRITE(), FPUTS(), etc. you need to have the text file open exclusively. This means that you cannot have two users writing to a text file at the same time. In other words, FOPEN() opens the textfile exclusively.

Note: If you attempt to open any file using FOPEN() it will attempt to open it for exclusive use - therefore, you can use FOPEN() as a test to see if a file has been opened by another user. This can be quite usefull in your PACK and REINDEX routine.
   lnHndl = FOPEN([Path2\MyTable.DBF])
   IF lnHndl > 0   && Table was opened so nobody else has it opened
      FCLOSE(lnHndl)
      ERASE [Path2\MyTable.CDX]
      USE [Path2\MyTable.DBF] IN 0 EXCLUSIVE 
      INDEX ON ... TAG MyTag
      ...
   ELSE
      && FOPEN() failed so do not attempt to reindex this table
      lcLog = lcLog + [REINDEX failed on MyTable]+ CHR(13)
   ENDIF


What are you doing that you need to have two people writing to a text file at the same time? If you want to have two people writing to the same file, have them write to a table rather than a text file - you can then create a text file from that table when ever you need it.

Ken
You shall know the truth - and the truth shall set you free. (John 8:33)

ENTIRE THREAD

Writing to text file Posted by Christian Pano @ 8/18/2006 3:54:59 PM
RE: Writing to text file Posted by Borislav Borissov @ 8/18/2006 4:01:27 PM
RE: Writing to text file Posted by Ken Murphy @ 8/18/2006 4:08:30 PM
RE: Writing to text file Posted by Christian Pano @ 8/18/2006 4:31:07 PM
RE: Writing to text file Posted by Ken Murphy @ 8/18/2006 6:02:17 PM
RE: Writing to text file Posted by Binod Binani @ 8/20/2006 5:48:56 AM
RE: Writing to text file Posted by tushar @ 8/20/2006 9:41:05 AM
RE: Writing to text file Posted by Ken Murphy @ 8/20/2006 2:21:20 PM