How to copy strings of consistent width in clipboard

Hey all, I am trying to export some table data in the clipboard and I’d like to get the formatting so the width is consistent. I have been using the following with just the number of spaces and it looks alright, but I’m sure someones got a better solution? Thanks!

[code]
Dim C as New Clipboard

Dim resultString As String

resultString = "Explosive Name: " + TextExplosiveName.Text + EndOfLine +EndOfLine _

  • “Manual” +APP.Space(50 - len(“manual”) ) + “Pressure” + APP.space(40 - len(“pressure”) ) + “Impulse” + APP.space(40 - len(“impulse”) )+ EndOfLine

For i As Integer = 0 To ListboxManualData.ListCount - 1

resultString = resultString + ListboxManualData.Cell(i,0) + APP.Space(40 - len(ListBoxManualData.Cell(i,0)) ) + ListboxManualData.Cell(i,1) + APP.space(40 - len(ListboxManualData.Cell(i,1)) ) + ListboxManualData.Cell(i,2) + EndOfLine

Next

C.Text = resultString

C.close[/code]

One of the things the tab key/character is for happens to be tabular data. Separate columns by tabs, and text programs designed to handle this appropriately will line the columns up.

I believe there’s even a hidden trick in Listbox where if you ask for the Cell value of -1, -1 you get the whole listbox content separated by tabs. Someone correct me if I’ve got something wrong there. Try resultString = ListboxManualData.Cell(-1, -1)

I would take the tabs approach because if the text editor isn’t displaying it properly, it’s the text editor. If you litter the data with spaces, the alignment can change for different font widths, and then you’ve also made the data harder to handle after the fact.

One other good thing about using tabs, is that you can paste the information to programs like Excel and will put each value on it’s own cell. With spaces each row will have all the data on the first column.

It all depends on your needs.

Thanks, Tim, I did not know
string = listbox.cell (-1, -1) is good

[quote=405281:@Tim Parnell]One of the things the tab key/character is for happens to be tabular data. Separate columns by tabs, and text programs designed to handle this appropriately will line the columns up.

I believe there’s even a hidden trick in Listbox where if you ask for the Cell value of -1, -1 you get the whole listbox content separated by tabs. Someone correct me if I’ve got something wrong there. Try resultString = ListboxManualData.Cell(-1, -1)

I would take the tabs approach because if the text editor isn’t displaying it properly, it’s the text editor. If you litter the data with spaces, the alignment can change for different font widths, and then you’ve also made the data harder to handle after the fact.[/quote]

Thanks a lot, that cell trick is really nifty

Make a module, call it ListboxExtensions

ListBox: Copy ListBox To Clipboard

[code]Public Sub CopyListBoxToClipBoard(Extends LB as ListBox)

dim c as new Clipboard

c.SetText LB.cell(-1,-1)

c.close

End Sub[/code]

ListBox: Copy Row To Clipboard

[code]Public Sub CopyRowToClipboard(Extends LB as ListBox, row as integer)

dim c as new Clipboard

c.SetText LB.cell( row, -1 )

c.close

End Sub[/code]

ListBox: Copy Colum To Clipboard

[code]Public Sub CopyColumToClipboard(Extends LB as ListBox, column as integer)

dim c as new Clipboard

c.SetText LB.cell(-1, column)

c.close

End Sub[/code]

[quote=405658:@Markus Winter]Make a module, call it ListboxExtensions

ListBox: Copy ListBox To Clipboard

[code]Public Sub CopyListBoxToClipBoard(Extends LB as ListBox)

dim c as new Clipboard

c.SetText LB.cell(-1,-1)

c.close

End Sub[/code]

ListBox: Copy Row To Clipboard

[code]Public Sub CopyRowToClipboard(Extends LB as ListBox, row as integer)

dim c as new Clipboard

c.SetText LB.cell( row, -1 )

c.close

End Sub[/code]

ListBox: Copy Colum To Clipboard

[code]Public Sub CopyColumToClipboard(Extends LB as ListBox, column as integer)

dim c as new Clipboard

c.SetText LB.cell(-1, column)

c.close

End Sub[/code][/quote]

Thanks, I just put it in a function, think I’ll use this module approach so I can use it in other projects easier.