Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2011
    Posts
    10

    Unanswered: Fixed Length Text File

    I am doing an output to a text file using


    StreamWriter.WriteLine(myText)

    The file get's created and records are written. Now, the problem is that this needs to be a fixed length text file. I am reading data retrieved from a stored procedure and looping through a data table to populate the text file like:



    For Each Row In myDataTable.Rows
    myText = myDataTable.Rows(i).Item(0).ToString() & _
    myDataTable.Rows(i).Item(1).ToString() & _

    Any suggestion to get a fixed length regardless what is filled from my data table?

  2. #2
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    Look into the Space function. Basically you want to add however many spaces to the end of your string that you need.

    This Pad function should be useful
    Code:
    function Pad(myString, desiredLength)
        Pad = myString + Space(desiredLength - Len(myString)
    end function
    The function is untested but it should be pretty close and give you enough to work on.

Posting Permissions

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