Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

STRTOFILE() but variable is >255 characters

Status
Not open for further replies.

chandler

MIS
Dec 10, 2000
66
US
I'm trying to create a header row for a comma delimited file using STRTOFILE(), but the variable for the cExpression property is greater than 255 characters. Is there a workaround?

Code:
&& Header Row
hdr='"FIRST","LAST","OR CURRENT RESIDENT","STREET","CITY","ST","ZIP4","JOBNUM","PART","OPT. ENDORSEMENT LINE","POSTNET BARC","SEQUENTI","SCH","STUDENTID","VAR1","VAR2","VAR3","ADKEY","CC","PHONE","URL","INTEREST","SEGMENT","SHELL","S","SCH_PRT","SCH_NAME","PR","VENDOR","V2ID","V3ID","GEN"'
	
hstr=hdr+chr(13)+chr(10)

&& Body
fstr=rstr&&+chr(13)+chr(10)

&& File name from array
nname = print_jobs(acnt,2)

&& Create delimited file
STRTOFILE(hstr,left(nname,len(nname)-4),.f.)
STRTOFILE(fstr,left(nname,len(nname)-4),.t.)

Chandler
I ran over my dogma with karma!
 
I tried your code and got an error on the first line. replaced it as follows and it run great in vfp9.

Code:
hdr = ["FIRST","LAST","OR CURRENT RESIDENT","STREET","CITY","ST",] + ;
	["ZIP4","JOBNUM","PART","OPT. ENDORSEMENT LINE","POSTNET BARC",] + ;
	["SEQUENTI","SCH","STUDENTID","VAR1","VAR2","VAR3","ADKEY","CC",] + ;
	["PHONE","URL","INTEREST","SEGMENT","SHELL","S","SCH_PRT","SCH_NAME",] + ;
	["PR","VENDOR","V2ID","V3ID","GEN"]

Furthermore, note that the 254 char limitation applies to fields and not memory variables.

Jean
 
Visual FoxPro allows for huge strings. I believe VFP9 maximum is limited by your amoutnof memory and cannot exceed about 2GB, the maximum size of files VFP can handle.

While the size of a string can be huge, the typed string in code or in the command window cannot be larger than 254 or 255 characters.

The fix that jesylv demonstrated above was to split the string into segments less than 256 characters, bypassing that literal-text-size limit. Besides, it's easier to read the code that way.

dbMark
 
Other way:
Code:
&& Header Row
TEXT TO m.Hdr NOSHOW PRETEXT 1+2+4+8
 "FIRST","LAST","OR CURRENT RESIDENT","STREET","CITY","ST",
 "ZIP4","JOBNUM","PART","OPT. ENDORSEMENT LINE","POSTNET BARC",
 "SEQUENTI","SCH","STUDENTID","VAR1","VAR2","VAR3","ADKEY",
 "CC","PHONE","URL","INTEREST","SEGMENT","SHELL","S",
 "SCH_PRT","SCH_NAME","PR","VENDOR","V2ID","V3ID","GEN"
ENDTEXT

Check TEXT ENDTEXT in help for values of PRETEXT becuase they vary with versions of VFP. The example PRETEXT is valid only for VFP9, for VFP8 the value can be 7 and you must manualy remove CRLF from variable.

Borislav Borissov
 
There are different limitations in effect:
-C Fields of tables up to 254 Characters
-string constants 255 characters.

The workaround for string constants is of course splitting and concatenating the smaller parts with +, or using TEXT...ENDTEXT.

If you have an older version you may simply strip off chr(13)+chr(10) from TEXT...ENDTEXT with CHRTRAN() afterwards.

Bye, Olaf.
 
The way I do it all the time is to break it up thus:

hdr='"FIRST","LAST","OR CURRENT RESIDENT","STREET","CITY",'
hdr=hdr+'"ST","ZIP4","JOBNUM","PART","OPT. ENDORSEMENT LINE"'
hdr=hdr+',"POSTNET BARC","SEQUENTI","SCH",'
hdr=hdr+'"STUDENTID","VAR1","VAR2","VAR3",'
hdr=hdr+'"ADKEY","CC","PHONE","URL","INTEREST",'
hdr=hdr+'"SEGMENT","SHELL","S","SCH_PRT",'
hdr=hdr+'"SCH_NAME","PR","VENDOR","V2ID","V3ID","GEN"'

Or, you can put the header in a text file and:

hdr=filetostr("header.txt")



 
Thanks everyone.
I'm going to end up putting the header in a text file because that takes care of making the change in quite a few other processes all over the department.

Chandler
I ran over my dogma with karma!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top