If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Fixed Length Text File

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-07-11, 05:47
veggiop veggiop is offline
Registered User
 
Join Date: Mar 2011
Posts: 10
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?
Reply With Quote
  #2 (permalink)  
Old 04-07-11, 23:28
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On