Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Ilya Rabyy
  Where is Ilya Rabyy?
 Fountain Valley
 California - United States
 Ilya Rabyy
 To: DEREK DODOO
  Where is DEREK DODOO?
 READING, UK
 United Kingdom
 DEREK DODOO
 Tags
Subject: RE: text file programming with CR LF
Thread ID: 143523 Message ID: 143544 # Views: 2 # Ratings: 1
Version: Visual FoxPro 6 Category: General VFP Topics
Date: Wednesday, August 29, 2007 5:10:45 PM         
   


> Dear All,
>
> I'd like to program the Carriage Return & the Line Feed, in generating a text file from a cursor as depicted below.
>
> I have problem exporting the text file when I created it with 'SDF' extension, hence this approach
>
> *****************************************************************
> ** The creation of the cursor and the textfile are as follows:
> 
> ** create cursor SALARY_PAY;
> 	(TRN_TYPE C(4), DEB_AC_NUM C(12), DEB_CURR C(3), DEB_AMT N(13,2), DEB_DATE ;
	D, CR_AcC_NUM C(12),ORDER_CUST C(3), PROF_CENT C(4), DEB_REF C(14), CED_REF C(14))
> 	select * from vpayroll where vpayroll.PERIOD=?bb_period and vpayroll.YEAR1=?	cc_year ;
> 	into cursor salary_hold
> 
> 	SELECT salary_hold.*, vpaymast11.sssno;
> 	FROM salary_hold;					
> 	LEFT OUTER JOIN vpaymast11  ON salary_hold.idno ==vpaymast11.idno  into 	CURSOR fin_rep
> 
> 	SELECT fin_rep.*, vdept.cost_center;
> 	FROM fin_rep;					
> 	LEFT OUTER JOIN vdept  ON fin_rep.dept ==vdept.dep_no  into CURSOR fin_rep1
> 	******************************creating the accounts 
> 	select fin_Rep1
> 	go top
> 		
> 	XXX=THISFORM.DIRM1.VALUE	
> 		
> 	SCAN
> 		select salary_pay
> *****************************************1		
> 		append blank
> 		replace trn_type with "ACSP"
> 		replace deb_ac_num with "PL64401"
> 		replace deb_curr with "ASD"
> 		replace deb_amt with FIN_REP1.BASICSAL
> 		replace deb_Date with DATE()
> 		replace cr_Acc_num with "ABC000000002"
> 		replace order_cust with "TRIAL"
> 		replace prof_cent with FIN_REP1.COST_CENTER
> 		replace deb_ref with "BASIC SALARY"
> 		replace ced_ref with "BASIC SALARY"
> ******************************************2	
> 		append blank
> 		replace trn_type with "ACSP"
> 		replace deb_ac_num with "PL44431"
> 		replace deb_curr with "ASD"
> 		replace deb_amt with FIN_REP1.SSFPLER
> 		replace deb_Date with DATE()
> 		replace cr_Acc_num with "UKA77770002"
> 		replace order_cust with "ASD"
> 		replace prof_cent with FIN_REP1.COST_CENTER
> 		replace deb_ref with "SSF EMPLOYER"
> 		replace ced_ref with "SSF EMPLOYER"
> ******************************************3			
> 		append blank
> 		replace trn_type with "ACSP"
> 		replace deb_ac_num with "PL66641"
> 		replace deb_curr with "UKA"
> 		replace deb_amt with FIN_REP1.PROVDER
> 		replace deb_Date with DATE()
> 		replace cr_Acc_num with "UKA333330002"
> 		replace order_cust with "ASD"
> 		replace prof_cent with FIN_rEP1.COST_CENTER
> 		replace deb_ref with "SSS EMPLOYER"
> 		replace ced_ref with "SSS EMPLOYER"
> 		
> 		select fin_rep1
> *******************************************************************
> *******************************************************************	
> ENDSCAN
> ********************************
> *********exporting file******(this approach is creating problems in importing system)
> ********************************
> SELECT SALARY_PAY
> 	COPY TO ABC  TYPE  SDF
> 	lcContents =FILETOSTR("ABC.TXT")
> 	STRTOFILE(CHRTRAN(lcContents,CHR(13)+CHR(10),""),"ABC.TXT")
> MODIFY FILE ABC.TXT

> I'd not like to use the 'SDF' extension.
>
> I'd like ASSISTANCE in the creation of the ABC.TXT file using CR & LF instead of the immediate above
>
> Thanks

Derek,
Two things I would recommend:

1. Make CRLF a constant with
#DEFINE  CR   CHR(13)
#DEFINE  LF   CHR(10)
#DEFINE  CRLF CR + LF

at the top of your PRG file (I presume it's a PRG module, isn't it?) Better yet - make it into H file (i.e. MyConstants.H) and then #INCLUDE "MyConstants" into your PRG files and Form/Include for your forms. Then, you can use these constants throughout your program.

2. In your code above, in the "Exporting file" section, I would have CHRTRAN() replaced with STRTRAN(), i.e.
SELECT SALARY_PAY
COPY TO ABC TYPE SDF
lcContents =FILETOSTR("ABC.TXT")
STRTOFILE(STRTRAN(lcContents,CRLF,""),"ABC.TXT")
MODIFY FILE ABC.TXT

Mind you that you will get the continuous string if you take off CRLF string terminator. Is it what you need?

HTH.

Regards,

Ilya

ENTIRE THREAD

text file programming with CR LF Posted by DEREK DODOO @ 8/29/2007 3:03:31 PM
RE: text file programming with CR LF Posted by tushar @ 8/29/2007 3:14:16 PM
RE: text file programming with CR LF Posted by DEREK DODOO @ 8/29/2007 3:54:56 PM
RE: text file programming with CR LF Posted by tushar @ 8/29/2007 4:14:36 PM
RE: text file programming with CR LF Posted by Cetin Basoz @ 8/29/2007 5:01:46 PM
RE: text file programming with CR LF Posted by Ilya Rabyy @ 8/29/2007 5:10:45 PM