Solved

Formatting a detail line while printing with FileSystemObject?

Posted on 2006-11-16
4
160 Views
Last Modified: 2010-04-16
I am creating a .txt file. I need to have each column fixed length. I am using the FileSystemObject where my final detail line is produced by the following line of code:

   strLine = strLocID  & "   " & strVendID & "   " & strDateTime & "   " & strProdID & "   " & strPrice
   ts.WriteLine strDetailLine

The file is created with no problem, however, the columns, row for row, do not line up exactly...meaning each column does not start in the exact column each time.

How can I fix this?

Thanks,
Blake
0
Comment
Question by:BlakeMcKenna
4 Comments
 
LVL 4

Expert Comment

by:hclgroup
ID: 17958797
I guess you need a function to pad your strings with spaces.
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 17958802
BlakeMcKenna,

If this is a plain text file then that must mean that the information in the "columns" are not the same length.  Either that or the text reader you are using is using a variable width font.  Does the length of the content differ (i.e. sometimes 8 characters other times 12 characters)?  Will the file be read by a person or are you making it for something else?  You seem to be using ASP/vbscript but please confirm that.

If this has to be a text file and be formatted visually (i.e. csv file won't work) then you may have to fix this in the text reader.  Your answers to my questions will help me verify this though.

Let me know if you have any questions or need more information.

b0lsc0tt
0
 
LVL 1

Accepted Solution

by:
DarrylRT earned 500 total points
ID: 17958896
I use 'space' when i'm building a flat file, for text items, and 'format' for numerical and date .  I plug the maximum number of characters for 'x'.

Space(x - Len(variable))

strLine = space(x - len(strLocID))  & "   " & space(x - len(strVendID)) & "   " & format(strDateTime,"yyyy/mm/dd") & "   " & space(x-len(strProdID)) & "   " & format(strPrice,"0000000000.00")

For the price, determine a max number of digits and decimals required.

Hope this helps.

Don
0
 

Author Comment

by:BlakeMcKenna
ID: 17959045
Ok, now things have changed. I am putting each data element into a Type array (which is defined in a .bas module) and I'm not getting a "Subscript out of range" error. I also need to sort this collection by the strLocID and I have no idea how to do this. Any ideas? Here is my code:

.bas Module Code:

Public Type DetailLine
    tLocID As String * 10
    tVendID As String * 16
    tDateTime As String * 13
    tProdID As String * 15
    tPrice As String * 8
End Type
Public typPNECDetail() As DetailLine



Form Module Code:

    idx = 0
   
    For Each objBlock In ReqColl
        For Each objProd In objBlock.Products
            Dim i As Integer
            For x = 0 To UBound(typAreas)
                If objBlock.AreaID = typAreas(x).AreaID Then
                    For i = 0 To UBound(typLocation)
                        If objBlock.Location = typLocation(i).advLocName Then
                            typPNECDetail(idx).tLocID = typLocation(i).pdsLocID             <<<<< subscript error >>>>>
                            Exit For
                        End If
                    Next i
                   
                    For i = 0 To UBound(typVendor)
                        If objBlock.Vendor = typVendor(i).advVendorName Then
                            typPNECDetail(idx).tVendID = typVendor(i).pdsVendorID
                            Exit For
                        End If
                    Next i
                   
                    For i = 0 To UBound(typProducts)
                        If objProd.Product = typProducts(i).advProdName Then
                            typPNECDetail(idx).tProdID = typProducts(i).pdsProdCode
                            Exit For
                        End If
                    Next i
                               
                    typPNECDetail(idx).tDateTime = Format(objProd.EffOnDateTime, "mmddyy hh:mm")
                    typPNECDetail(idx).tPrice = objProd.Price
                    ts.WriteLine typPNECDetail(idx).tLocID & typPNECDetail(idx).tVendID & typPNECDetail(idx).tDateTime & 
                                      typPNECDetail(idx).tProdID & typPNECDetail(idx).tPrice
                    idx = idx + 1
                    Exit For
                End If
            Next x
        Next
    Next


thanks,
Blake
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show, step by step, how to integrate R code into a R Sweave document
This is about my first experience with programming Arduino.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question