Set Optimize On Select New_Bills Scan && Scans for New_bills up to EOF() cPsfilepath=Alltrim(Fullpath) Newpath=Alltrim(Newpath) Create Cursor Cursor_AllBills (POS varchar(254),PAGENUM I,posR N(8,3),posC N(8,3)) && Create Temporary Cursor For Cursor_AllBills Select Cursor_AllBills Append From (m.cPsfilepath) Sdf Locate For Alltrim(POS)='%%EndSetup:' HeaderRecordNumber=Recno() && Finds the Header Record Number for Each PS File SELECT POS FROM Cursor_AllBills INTO CURSOR Cursor_Header Where Recno()<= HeaderRecordNumber Delete From Cursor_AllBills Where Recno()<= HeaderRecordNumber Do Split ENDSCAN PROCEDURE Split Select New_Bills Scan && Scans for New_bills up to EOF() cPsfilepath=Alltrim(Fullpath) Newpath=Alltrim(Newpath) Create Cursor Cursor_AllBills (POS varchar(254),PAGENUM I,posR N(8,3),posC N(8,3)) && Create Temporary Cursor For Cursor_AllBills Select Cursor_AllBills Append From (m.cPsfilepath) Sdf Locate For Alltrim(POS)='%%EndSetup:' HeaderRecordNumber=Recno() && Finds the Header Record Number for Each PS File SELECT POS FROM Cursor_AllBills INTO CURSOR Cursor_Header Where Recno()<= HeaderRecordNumber Delete From Cursor_AllBills Where Recno()<= HeaderRecordNumber Do Split Endscan *Now We will Split and Compress it Procedure Split Select Cursor_AllBills Select Count(POS) From Cursor_AllBills Where Left(Alltrim(POS),9)='%%Page: 1' ; Into Array nNumberofbillsincurrentfile && Counts The Number of Bills in Current File nBillend=0 && Start Position for Searching Location of %%Page: 1 For I=1 To m.nNumberofbillsincurrentfile && Loop to Separate Each Bill and Compress it. Select Cursor_AllBills Locate For Left(Alltrim(POS),9)='%%Page: 1' And Recno()>m.nBillend nPageonestart=Recno() Locate For Left(Alltrim(POS),9)='%%Page: 2' And Recno()>m.nPageonestart nPageoneend=Recno() Locate For Left(Alltrim(POS),9)='%%Page: 1' And Recno()>m.nPageoneend nBillend=Recno() Select * From Cursor_AllBills Into Cursor Cursor_Splitedfile Where Recno()=>m.nPageoneend And Recno()<m.nBillend Readwrite Locate For Strextract(POS,'(',')')='Account Number' Skip oFileName=Strextract(POS,'(',')') oFileName='C:\HARSH\'+oFileName+'.Ps' *** Here the Size of POS exceeds 255 hence we will delete some ... to make it below 255 CHaracter Locate For Right(Alltrim(POS),9)='. . . .)S' IF Found() Replace POS With Left(Alltrim(POS),250)+'.)SH' Endif Select Count(POS) From Cursor_Splitedfile Where Left(Alltrim(POS),7)='%%Page:' Into Array lnPagecount Select Cursor_Splitedfile nAssignpagenumberRecno=0 For nAssignpagenumber=1 To m.lnPagecount Locate For Left(Alltrim(POS),7)='%%Page:' And Recno()>m.nAssignpagenumberRecno If Found() nAssignpagenumberRecno=Recno() Replace POS With '%%Page: '+Alltrim(Str(m.nAssignpagenumber))+' '+Alltrim(Str(m.lnPagecount)) Endif Endfor Set Textmerge On Set Textmerge To (m.oFileName) Noshow Scan \\<< TRIM(POS) >> \ Endscan Set Textmerge To Set Textmerge Off WAIT WINDOW I Nowait Endfor Return Endproc>Hi Harsh
>>SELECT ALLBILLS >>SELECT COUNT(POS) FROM Allbills WHERE LEFT(ALLTRIM(pos),9)='%%Page: 1' INTO ARRAY nNumberofbillsincurrentfile >>nBillend=0 >>FOR I=1 TO m. nNumberofbillsincurrentfile >>SELECT AllBILLS >>LOCATE FOR LEFT(ALLTRIM(POS),9)='%%Page: 1' AND RECNO()>m.nBillEnd && Bill Starts From Here and This is the First Page >>nPageonestart=RECNO() >>LOCATE REST FOR LEFT(ALLTRIM(POS),9)='%%Page: 2' AND RECNO()>m.nPageonestart && Page One Ends Here >>nPageoneend=RECNO() >>LOCATE REST FOR LEFT(ALLTRIM(POS),9)='%%Page: 1' AND RECNO()>m.nPageoneend && Next Bills Starts From Here >>nBillEnd=RECNO() > >GO m.nPageOneEnd >lcFileName = STREXTRACT(POS,'(',')') > >>LOCATE REST FOR STREXTRACT(POS,'(',')')='Account Number' AND RECNO()>m.nPageoneend AND RECNO()<m.nBillend >>SKIP > > >Don't use oFilename. o is usually used for an object variable type. This will be very confusing. It should be cFileName >>cFileName=STREXTRACT(POS,'(',')') >>cFileName='D:\HARSH\'+oFileName+'.Ps' > >Are you near the record you want below after the SKIP above? LOCATE FOR cannot optimize the following without an index. But if the next few records after the above contains the string you seek, you could do LOCATE REST FOR and it will get there really fast. > >>LOCATE REST FOR ALLTRIM(POS)="20.699 184.238 MV (. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .)S" >>Replace POS WITH '20.699 184.238 MV (. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . )SH' > >If the above is really what you mean to do, it seems the only difference is adding an H to the end of POS. Here's how: >REPLACE POS WITH ALLTRIM(POS) + "H" > > >SELECT cannot use RECNO() to optimize. DO NOT ADD AN INDEX ON RECNO()!!! Very dangerous. >>SELECT POS FROM Allbills INTO CURSOR Splitfile Where RECNO()=>m.nPageoneend AND RECNO()<m.nBillEnd Readwrite > >I think you might try.. >GO m.nPageoneend >COPY REST TO splitfile.DBF WHILE RECNO()<m.nBillEnd >USE splitfile in select("splitfile") >SELECT splitfile > >>Set Textmerge ON >>Set Textmerge To (m.cFileName) Noshow >>SCAN >>\\<< TRIM(POS) >> >>\ >>ENDSCAN >>Set Textmerge To >>Set Textmerge OFF > > > >*DO NOT EVER USE RECNO() with SQL commands. >>DELETE FROM Allbills Where RECNO()=>m.nPageonestart AND RECNO()<=m.nBillEnd > >Do this instead. > >SELECT ALLBILLS >GO m.nPageOneStart >DELETE REST WHILE RECNO()<=m.nBillEnd > > >>WAIT WINDOW I Nowait >>ENDFOR >>