How to copy strings of consistent width in clipboard

  1. 2 months ago
    Edited 2 months ago

    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!

    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

    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.

  2. Tim P

    Sep 12 Pre-Release Testers Answer feedback://46303

    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.

  3. Alberto D

    Sep 12 Pre-Release Testers, Xojo Pro

    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.

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

  5. 8 weeks ago

    @Tim P 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.

    Thanks a lot, that cell trick is really nifty

  6. Markus W

    Sep 14 Pre-Release Testers, Xojo Pro #JeSuisHuman Germany, Heidelb...

    Make a module, call it ListboxExtensions

    ListBox: Copy ListBox To Clipboard

    Public Sub CopyListBoxToClipBoard(Extends LB as ListBox)
    
      dim c as new Clipboard
      
      c.SetText LB.cell(-1,-1)
      
      c.close
      
    End Sub

    ListBox: Copy Row To Clipboard

    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

    ListBox: Copy Colum To Clipboard

    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
  7. @Markus W Make a module, call it ListboxExtensions

    ListBox: Copy ListBox To Clipboard

    Public Sub CopyListBoxToClipBoard(Extends LB as ListBox)
    
      dim c as new Clipboard
      
      c.SetText LB.cell(-1,-1)
      
      c.close
      
    End Sub

    ListBox: Copy Row To Clipboard

    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

    ListBox: Copy Colum To Clipboard

    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

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

or Sign Up to reply!