Link to home
Start Free TrialLog in
Avatar of jigdog
jigdogFlag for United States of America

asked on

Formatting Columns in Text File (StreamWriter for VB.NET)

Ok, i need to format columns in a simple text file that is then sent to a PrintPreviewDialog ...but my columns will not line up.  I wrote a custom 'spacer' ... then I tried the StreamWriter's built in formatting ... it WILL NOT line up.  The current code is below, and the output.


Dim TempFile As New System.IO.StreamWriter("temp")
        TempFile.WriteLine("Invoice")
        TempFile.WriteLine("Customer: " & CustomerName)
        TempFile.WriteLine("Order #: " & OrderNumber)
        TempFile.WriteLine()
        TempFile.WriteLine("{0,15}{1,15}{2,15}{3,15}{4,15}{5,15}", "Quantity", "Size", "Monogram", "Pocket", "Price Each", "Total Price")

        For I As Integer = 0 To 140
            TempFile.Write("-")
        Next

        TempFile.WriteLine()

        For Each Order As OrderEntry In OrderEntries

            If Order.Quantity <> 0 Then

                TempFile.Write("{0,15}", CStr(Order.Quantity))
                TempFile.Write("{0,15}", Order.Size)

                If Order.Monogram Then
                    TempFile.Write("{0,15}", "YES")
                Else
                    TempFile.Write("{0,15}", "NO")
                End If

                If Order.Pocket Then
                    TempFile.Write("{0,15}", "YES")
                Else
                    TempFile.Write("{0,15}", "NO")
                End If

                TempFile.Write("{0,15}", Order.Price.ToString("C"))
                TempFile.WriteLine("{0,15}", Order.ExtendedPrice.ToString("C"))
            End If


        Next
        TempFile.Close()

Open in new window

Capture.JPG
ASKER CERTIFIED SOLUTION
Avatar of Paul_Harris_Fusion
Paul_Harris_Fusion
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jigdog

ASKER

Luckily, as this is not a professional/paid project, attractiveness is not an issue.  Your explanation is what I needed, and 'Courier New' allowed me to get the alignment correct.  Thanks so much!