>Hello all;
>I wrote a prg that opens a text file, reads each line, parses the line and writes it into another file. the program works fine but it takes to long.
>is there a method that i can accomplish this quicker.
>A file that is about 250,000 lines takes almost 2 hours to process. Below is my prg and a few lines of the data from the input file.
>the program creates a new line after every tilde.
>
>the parameter are the file handles created with a Fopen() and fcreate()
>
>PARAMETERS gnInFile, gnOutFile
>LOCAL lnEnd,lnStrt,lnLoop,lcString
>
>lnEnd = FSEEK(gnInFile,0,2)
>lnEndLoop = lnEnd + 1
>lnStrt = FSEEK(gnInFile,0)
>lnLoop = 0
>lcString = FGETS(gnInFile,64)
>
>FOR lnLoop = 1 TO lnEndLoop
> * lnLoop = FSEEK(gnInFile,0,1)
> WAIT WINDOW "Processing byte " + ALLTRIM(STR(lnLoop)) + " of " + ALLTRIM(STR(lnEnd)) NOWAIT
>
> IF AT('~',lcString,1) > 0
> =FPUTS(gnOutFile,SUBSTR(lcString,1,AT('~',lcString,1)))
> lcString = SUBSTR(lcString,AT('~',lcString,1)+1)
> ELSE
> lcString = lcString + FGETS(gnInFile,64)
> ENDIF
>
> lnLoop = FSEEK(gnInFile,0,1)
> IF lnLoop = lnEnd AND (EMPTY(lcString) OR ISBLANK(lcString))
> EXIT
> ENDIF
>ENDFOR
>
>sample of character in the input file. We must create a new line at every Tilde. ~
>
>ISA*00* *00* *ZZ*341884003 *ZZ*113284753 *110215*1703*U*00401*104605543*0*P*>~GS*HC*341884003*113284753*20110215*1703*104605543*X*004010X098A1~ST*837*0001~BHT*0019*00*1046055430001*20110215*1127*CH~REF*87*004010X098A1~NM1*41*2*INTERACTIVE PAYER NETWORK*****46*341884003~PER*IC*EMDEON ADVANCED CLAIMING*TE*6159323021*EM*CLEPRODUCTIONTEAM@EMDEON.COM~NM1*40*2******46*113284753~HL*1**20*1~NM1*85*2*PRAKASHCHANDRA M. RAO, M.D., P*****XX*1326296039~N3*3130 GRAND CONCOURSE~N4*BRONX*NY*10458~REF*EI*010567880~REF*G5*0001~REF*G2*101439~HL*2*1*22*1~SBR*P**999999******ZZ~NM1*IL*1*FUENTES*JUANUTA****MI*16705189~N3*1770 BRUCKNER BLVD*13B~N4*BRONX*NY*10473~DMG*D8*19400518*F~NM1*PR*2*HERITAGE*****PI*11328~HL*3*2*23*0~PAT*21~NM1*QC*1*FUENTES*JUANITA
>
>Thank you in advance for your time and efforts.
Take a look at my comment. If you re-construct the string in every operation, it should be slow. You may want to read one line at a time and then perform additional modifications using alines() function. Also, you can do a look with while not FEOF - it should be better than going to the end the way you do.
If it's not broken, fix it until it is.
My Blog