Results 1 to 4 of 4

Thread: [RESOLVED] Text File Columns

  1. #1

    Thread Starter
    Frenzied Member toecutter's Avatar
    Join Date
    Apr 2006
    Location
    Brisbane, Australia
    Posts
    1,160

    Resolved [RESOLVED] Text File Columns

    Ive been trying to use the "ControlChars.Tab" to sort the strings into columns with code from this forum.
    Code:
        Public Sub save()
            'http://www.vbforums.com/showthread.php?t=366421&highlight=listview+textfile
            Try
                Dim sw As New IO.StreamWriter("C:\StickFrameExpress\Jobs\" & Me.lblJobNumber.Text & ".txt", True)
                'header
                sw.WriteLine("Component Name, Material Type, Length, Quanitiy, Units, NOTE:")
                Dim i As Int16
                With Me.ListView1
                    For i = 0 To CShort(.Items.Count - 1)
                        If .Items(i).Text <> "" Then
                            sw.WriteLine(.Items(i).Text & _
                            ControlChars.Tab & _
                            ControlChars.Tab & .Items(i).SubItems(1).Text & _
                            ControlChars.Tab & _
                            ControlChars.Tab & .Items(i).SubItems(2).Text & _
                            ControlChars.Tab & _
                            ControlChars.Tab & .Items(i).SubItems(3).Text & _
                            ControlChars.Tab & _
                            ControlChars.Tab & .Items(i).SubItems(4).Text & _
                            ControlChars.Tab & _
                            ControlChars.Tab & .Items(i).SubItems(5).Text)
                        End If
                    Next
                End With
                sw.Close()
                Me.ListView1.Clear()
            Catch ex As Exception
            End Try
        End Sub
    I tried using "ControlChars.Tab" multibly times but as the individual string change in size the column do not line up.




    Should i been working with "ControlChars.Tab" for this or something else?

    cheers
    toe

  2. #2
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Text File Columns

    Change the font to a mono spaced one, Lucida or Courier come to mind.

    You could also try making all of the items the same length.

    Code:
    sw.WriteLine(.Items(i).Text.PadRight(10, " "c) & _
                            ControlChars.Tab & _
                            ControlChars.Tab & .Items(i).SubItems(1).Text.PadRight(10, " "c) & _
                            ControlChars.Tab & _
                            ControlChars.Tab & .Items(i).SubItems(2).Text.PadRight(10, " "c)
    Last edited by dbasnett; Apr 12th, 2008 at 06:14 PM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  3. #3

    Thread Starter
    Frenzied Member toecutter's Avatar
    Join Date
    Apr 2006
    Location
    Brisbane, Australia
    Posts
    1,160

    Re: Text File Columns

    thanks dbasnett

  4. #4
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [RESOLVED] Text File Columns

    Finally I did some good today. You are welcome!
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width