Hi Ted,

Here's another version which gets round the problem of embedded commas:

#DEFINE CTAB CHR(9)
#DEFINE CRLF CHR(13)+CHR(10)
LOCAL lcc As String, i As Integer, n As Integer
SET SAFETY OFF
SELECT * FROM <table> WHERE <somewhere> INTO CURSOR tmp
*!* Trim varchar fields if required
*!* CTOV("tmp")
COPY TO tmptxt.txt TYPE DELIMITED WITH TAB
n = FCOUNT()
lcc = ""
FOR i = 1 TO n
lcc = lcc + FIELD(i) + CTAB
ENDFOR
lcc = LEFT(lcc, LEN(lcc) - 1) + CRLF + FILETOSTR("tmptxt.txt")
*!* Optionally remove quotes
*!* _CLIPTEXT = STRTRAN(lcc, ["])
_CLIPTEXT = lcc
STRTOFILE(_CLIPTEXT, "tmptxt.txt", 0)
MODIFY FILE tmptxt.txt
SET SAFETY ON

Laurie

On 18 July 2015 at 10:03, Laurie Alvey <[email protected]> wrote:

> Hi Ted,
>
> This seems to work:
> LOCAL lcc As String
> SET SAFETY OFF
> SELECT * FROM <table> WHERE <something> INTO CURSOR tmp
> COPY TO tmptxt.txt TYPE CSV
> lcc = FILETOSTR("tmptxt.txt")
> lcc = STRTRAN(lcc, ",", CHR(9)) && replace commas with tabs
> _CLIPTEXT = lcc
> STRTOFILE(_CLIPTEXT, "tmptxt.txt", 0)
> MODIFY FILE tmptxt.txt
> SET SAFETY ON
>
> If you've got embedded commas in the columns, it won't work.
>
> Laurie
>
> On 18 July 2015 at 09:19, Laurie Alvey <[email protected]> wrote:
>
>> Hi Ted,
>>
>> Running CTOV("somecursor") certainly TRIMs the varchar columns (browse
>> the cursor and print LEN(somevarcharcolumn)). It looks like
>> _VFP.DataToClip() is repadding.
>>
>> I'll try something else.
>>
>> Laurie
>>
>> On 17 July 2015 at 16:06, Ted Roche <[email protected]> wrote:
>>
>>> Laurie:
>>>
>>> On Fri, Jul 17, 2015 at 5:50 AM, Laurie Alvey <[email protected]>
>>> wrote:
>>> > When I posted the CTOV function, you quite rightly pointed out that it
>>> > wouldn't solve the DataToClip problem. I meant to say the code should
>>> look
>>> > something like this:
>>> > SELECT something FROM somewhere INTO CURSOR somecursor
>>> > CTOV(somecursor)
>>> > _VFP.DataToClip(somecursor,3)
>>> >
>>>
>>> when you run this code, do you see the result in the clipboard trimmed
>>> to the actual lengths of the strings? On my machine, the strings seem
>>> to be padded out with spaces to their VarChar length. Pasting them
>>> into LibreOffice Calc or editing them in VFP using:
>>>
>>> StrToFile(_cliptext,"output.txt")
>>> modi file output.txt
>>>
>>> seems to show the fields are still padded.
>>>
>>>
>>> --
>>> Ted Roche
>>> Ted Roche & Associates, LLC
>>> http://www.tedroche.com
>>>
[excessive quoting removed by server]

_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: 
http://leafe.com/archives/byMID/profox/camvtr9ck0kcniwchdu0tqnxtozqpetjqqjt6zh9mgsn9tem...@mail.gmail.com
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to