Click here to Skip to main content
15,890,123 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralMessage Closed Pin
5-May-09 4:04
vijay24825-May-09 4:04 
GeneralRe: Append ALL Textfiles within a folder to a Single Textfile Pin
riced5-May-09 6:47
riced5-May-09 6:47 
GeneralRe: Append ALL Textfiles within a folder to a Single Textfile Pin
vijay24825-May-09 10:24
vijay24825-May-09 10:24 
GeneralRe: Append ALL Textfiles within a folder to a Single Textfile [modified] Pin
vijay24825-May-09 21:29
vijay24825-May-09 21:29 
GeneralRe: Append ALL Textfiles within a folder to a Single Textfile Pin
riced5-May-09 22:08
riced5-May-09 22:08 
GeneralRe: Append ALL Textfiles within a folder to a Single Textfile Pin
vijay24825-May-09 22:40
vijay24825-May-09 22:40 
GeneralRe: Append ALL Textfiles within a folder to a Single Textfile Pin
vijay24825-May-09 23:02
vijay24825-May-09 23:02 
GeneralRe: Append ALL Textfiles within a folder to a Single Textfile Pin
riced5-May-09 23:35
riced5-May-09 23:35 
Here's my version of how to write headers and change column spacing.
I realised there was a flaw in WriteHeaders() since the code that calls it had already read the first line.

Using sr As StreamReader = New StreamReader(inputFile, System.Text.Encoding.Default)
   If (fileCount = 0) Then
      'Read the first line of first file to set up column positions array
      inputLine = sr.ReadLine()
      Call GetColumnPostions(columnPositions, inputLine)
      If doHeaders Then
         Call WriteHeaders(inputLine, sr, sw, columnPositions)
      Else
         'Read and throw away second header line
         inputLine = sr.ReadLine()
      End If
   Else
      'Read the first line of file to set up column positions array
      'NOTE: This could produce columns that don't line up properly
      inputLine = sr.ReadLine()
      Call GetColumnPostions(columnPositions, inputLine)
      ' Read the remaining header lines and throw them away
      For i As Integer = 2 To 2 'Assumes 2 header lines, as does WriteHeaders
         inputLine = sr.ReadLine()
      Next
   End If

   'Now read and write the data lines
   While sr.Peek() >= 0
      inputLine = sr.ReadLine()
      outputLine = GetOutputLine(inputLine, createdAt, columnPositions)
      sw.WriteLine(outputLine)
   End While
End Using

Private Sub WriteHeaders(ByVal temp As String, ByVal sa As StreamReader, ByVal sw As StreamWriter, ByVal p As Integer())
   Dim sb As StringBuilder = BuildLine(temp, p)
   sb.Append("CREATED_DATE")
   sw.WriteLine(sb.ToString())   'First header line
   sw.WriteLine(sa.ReadLine())   'Second header line
End Sub

Not sure if this is what you meant by changing column positions. And it could produce output where columns don't line up properly.
The problem is that if, for example, the column positions in second file are greater than in first file you can't go back and re-write the output that's already been done. If they are less than in first file then the columns won't line up.
One way to make sure columns line up would be to change GetColumnPositions to use hard coded values (or pick them up from a file that is not one of the data files). That would mean you would not have to do a readline before calling GetColumnPositions, which would allow you to use the original WriteHeaders() that reads the first line.

How does your code write "CREATED_DATE" as column head?

Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis

GeneralRe: Append ALL Textfiles within a folder to a Single Textfile Pin
vijay24825-May-09 23:53
vijay24825-May-09 23:53 
GeneralRe: Append ALL Textfiles within a folder to a Single Textfile Pin
vijay24826-May-09 0:08
vijay24826-May-09 0:08 
GeneralRe: Append ALL Textfiles within a folder to a Single Textfile Pin
Dave Kreskowiak4-May-09 4:07
mveDave Kreskowiak4-May-09 4:07 
QuestionCOM port Pin
Subjugate3-May-09 21:07
Subjugate3-May-09 21:07 
AnswerRe: COM port [modified] Pin
Wankel Maggot3-May-09 21:48
Wankel Maggot3-May-09 21:48 
AnswerRe: COM port Pin
Bharat Jain3-May-09 21:50
Bharat Jain3-May-09 21:50 
GeneralRe: COM port Pin
Subjugate4-May-09 15:00
Subjugate4-May-09 15:00 
QuestionVisual Data Manager Pin
KULKING3-May-09 21:03
KULKING3-May-09 21:03 
AnswerRe: Visual Data Manager Pin
Henry Minute4-May-09 2:45
Henry Minute4-May-09 2:45 
Questioncan picture boxes be mathmatically different then they appear Pin
Wankel Maggot3-May-09 20:34
Wankel Maggot3-May-09 20:34 
AnswerRe: can picture boxes be mathmatically different then they appear Pin
Christian Graus3-May-09 22:19
protectorChristian Graus3-May-09 22:19 
GeneralRe: can picture boxes be mathmatically different then they appear Pin
Wankel Maggot3-May-09 22:30
Wankel Maggot3-May-09 22:30 
GeneralRe: can picture boxes be mathmatically different then they appear Pin
Christian Graus3-May-09 22:48
protectorChristian Graus3-May-09 22:48 
AnswerRe: can picture boxes be mathmatically different then they appear Pin
Luc Pattyn3-May-09 23:05
sitebuilderLuc Pattyn3-May-09 23:05 
GeneralRe: can picture boxes be mathmatically different then they appear Pin
Wankel Maggot3-May-09 23:33
Wankel Maggot3-May-09 23:33 
GeneralRe: can picture boxes be mathmatically different then they appear Pin
Luc Pattyn3-May-09 23:48
sitebuilderLuc Pattyn3-May-09 23:48 
GeneralRe: can picture boxes be mathmatically different then they appear Pin
Christian Graus4-May-09 0:04
protectorChristian Graus4-May-09 0:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.