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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String too long tofit 1

Status
Not open for further replies.

foxup

Programmer
Dec 14, 2010
328
CA
Hi All,

I'm getting "string too long to fir error" when I do this code:

FOR i = 1 TO THISFORM.List1.LISTCOUNT
IF THISFORM.List1.SELECTED(i)
lcMessage = lcMessage + THISFORM.List1.LIST(i) + CHR(13)
IF !EMPTY(lcMessage)
xcount=xcount+1
ENDIF
ENDIF
NEXT
cThisFileStr=''
cOutputFileStr = ""

FOR i = 1 TO THISFORM.List1.LISTCOUNT
IF THISFORM.List1.SELECTED(i)
cThisFileStr = FILETOSTR(THISFORM.List1.LIST(i))
cOutputFileStr = cOutputFileStr + cThisFileStr &&MERGE
ENDIF
NEXT
cOutputFile = "weektodo.csv"
=STRTOFILE(cOutputFileStr,cOutputFile) && get error here when it creates output file.

The files I am merging are pretty large (which is what I'm guesing is the problem), but I thought the cOutputFileStr = cOutputFileStr + cThisFileStr would have helped. it did not.

Is there anything that can be done to remedy this?

Please help.

Thanks,
FOXUP
 
The message means just what it says. Clearly, you are adding the contents of multiple files into the variable cOutputFileStr. the maximum size of a string variable is 16,777,184. If the total size of the text in those files exceeds that figure, you will get the error.

There are several other ways of achieving your goal. The easiest is probably to write to the output file each time you go round the FOR loop, rather than just once at the end. Set the nFlag parameter in STRTOFILE() to 1, to indicate that you want to append the contents each time.

Other options would be to use low-level file access, or to use the DOS Copy command.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Just to clarify my first suggestion, your second chunk of code would look something like this:

Code:
cOutputFile = "weektodo.csv"
FOR i = 1 TO THISFORM.List1.LISTCOUNT
    IF THISFORM.List1.SELECTED(i)
        cThisFileStr = FILETOSTR(THISFORM.List1.LIST(i))
        STRTOFILE(cThisFileStr, cOutputFile, 1)     
    ENDIF
NEXT

Note that I haven't tested this, so cannot guarantee it is correct, but it should give you the general idea.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Or, if for any reason that doesn't work, here is my DOS-based suggestion:

Code:
lcCommand = "Copy /a " 
FOR i = 1 TO THISFORM.List1.LISTCOUNT
    IF THISFORM.List1.SELECTED(i)
        lcCommand = lcCommand + THISFORM.List1.LIST(i) + " +"         
    ENDIF
NEXT
lcCommand = RTRIM(lcCommand, "+") + " " + "weektodo.csv"
RUN (lcCommand)

Again, this is not tested, so no guarantees.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Great Job Mike, as usual. Works like charm. Thank you. Star for you !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top