Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Formatting a detail line while printing with FileSystemObject?

Posted on 2006-11-16
4
161 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

839 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