copy and past as csv string.

I have some code that takes a listbox and when select all / copy is done a string is created that is supposed to look like:

[quote]data, data, data, data, carriage_return+line_feed
data, data, data, data, carriage_return+line_feed
data, data, data, data, carriage_return+line_feed
data, data, data, data, carriage_return+line_feed
data, data, data, data, carriage_return+line_feed[/quote]

When I look at the string in the debugger the cr/lf pair look correct in binary 0D 0A, they look like question marks in a diamond in the text display of the string…
But when I paste it from the clipboard the recipient says it can’t paste the data.

[code]Function EditCopy() As Boolean
dim r,c as integer
dim cb as new Clipboard
dim line as string=""
dim lines as string=""

// Heading row
for c=0 to me.ColumnCount-1
if lines <> “” then lines = lines + “,”
lines = lines + me.Heading©
next
lines = lines + chr(&h0d) + chr(&h0a)

// rows
for r=0 to me.lastindex
if me.Selected® = true then
line = “”
for c=0 to me.ColumnCount-1
if line <> “” then line = line + “,”
line = line + me.Cell(r, c)
next
lines = lines + line + chr(&h0d) + chr(&h0a)
end if
next

// Copy to clip board
cb.Text=lines
cb.Close
System.DebugLog(“data copied to Clipboard”)
Return True

End Function
[/code]

What are you pasting it into?

excel.

What OS? It works for me on Windows 7. Be aware that if you want each piece of data in a separate cell, you should use tabs, not commas.

Thanks Tim.
I need this to work on linux, mac and windows… however my development and test platform at the moment is OS X.

And really it’s text so if I paste it into emacs it should work… and it doesn’t.

Well I just tried this on OS X with MS Excel 2011
I just put this in the open event of the default window of a brand new project
I have NO list box so I hard coded column & row counts as well as the data that was being sent

[code] dim r,c as integer
dim cb as new Clipboard
dim line as string=""
dim lines as string=""

// Heading row
for c=0 to 10
if lines <> “” then lines = lines + chr(9)
lines = lines + str©
next
lines = lines + EndOfLine.Windows

// rows
for r=0 to 10
line = “”
for c=0 to 8
if line <> “” then line = line + chr(9)
line = line + str® + “:” + str©
next
lines = lines + line + EndOfLine.Windows

next

// Copy to clip board
cb.Text=lines
[/code]

This gives me TAB separated clipboard data & it pastes as rows & columns into Excel just fine here.
It pastes into Word, BBEdit and Textedit with tabs all intact.
Pasting it into Emacs running in terminal I get the text but emacs doesn’t do anything with the tabs.