Click here to Skip to main content
15,899,679 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Append ALL Textfiles within a folder to a Single Textfile Pin
riced5-May-09 2:30
riced5-May-09 2:30 
GeneralRe: Append ALL Textfiles within a folder to a Single Textfile Pin
riced5-May-09 1:18
riced5-May-09 1:18 
GeneralRe: Append ALL Textfiles within a folder to a Single Textfile Pin
vijay24825-May-09 1:59
vijay24825-May-09 1:59 
GeneralRe: Append ALL Textfiles within a folder to a Single Textfile Pin
riced5-May-09 2:12
riced5-May-09 2:12 
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 
Good Morning David,
My question is how to call the pF() without reading the file.
Private Sub FillPF(ByVal pF() As Integer, ByVal temp As String)
        pF(0) = temp.IndexOf("Nom du Modèle")
        pF(1) = temp.IndexOf("AEC_COMPATIBILITY")
        pF(2) = temp.IndexOf("AEC_STANDARD_DESCRIPTION_FRENCH")
        pF(3) = temp.IndexOf("AEC_FREE_DESCRIPTION_FRENCH")
        pF(4) = temp.IndexOf("AWW_STANDARD_DESCRIPTION")
        pF(5) = temp.IndexOf("AEC_FREE_DESCRIPTION_ENGLISH")
        pF(6) = temp.IndexOf("AEC_ECN")
        pF(7) = temp.IndexOf("DNF")
        pF(8) = temp.IndexOf("REP_DNF")
        pF(9) = temp.IndexOf("REP_ASM")
    End Sub

Call pF(pF,temp)

Before calling i should read the line using temp variable like "temp=sa.ReadLine()"
Since streamreader comes after this line,its not possible to call pF()
Modified version of the Code:
Private Sub AppendFiles(ByVal iFile As String, ByVal oFile As String)
        Dim temp As String
        Dim name As String
        Dim comp As String
        Dim desF As String
        Dim desAF As String
        Dim desA As String
        Dim desAA As String
        Dim ecn As String
        Dim dnf As String
        Dim repDNF As String
        Dim repASM As String
        Dim pF(10) As Integer
        Dim NbOfSpaces As Integer = 0
        Dim inputline As String
        Dim theDir As DirectoryInfo = New DirectoryInfo(iFile)
        Dim datFiles As FileInfo() = theDir.GetFiles("*.txt")
        Using sw As StreamWriter = New StreamWriter(oFile, True, System.Text.Encoding.Default)
            '--------------------------------------------------------------------------------------------' 
            'Call FillPF sub here, or move the code marked XXXX to here (I've done that). You don't need any files to do what it does
            'inputline = sa.readline()
            Call FillPF(pF, inputline)
            '--------------------------------------------------------------------------------------------
            '---------------------------------------------------------------------------------------------     
            'Read and write first file including headers 
            '*** iFile is the path, we've been through this before; StreamReader reads a file it can't read a folder
            '*** Change the name to something like inputPath and it will be less misleading.     
            'Using sa As StreamReader = New StreamReader(inputfile, System.Text.Encoding.Default)
            Dim fi1 As FileInfo = datFiles(0)
            Using sa As StreamReader = New StreamReader(fi1.FullName, System.Text.Encoding.Default)
                '-----------------------------------------------------------------------
                'This block reads and writes the two header lines in the first file
                '-----------------------------------------------------------------------  
                temp = sa.ReadLine()
                name = temp.Substring(0, pF(1))
                comp = temp.Substring(pF(1), pF(2) - pF(1))
                desF = temp.Substring(pF(2), pF(3) - pF(2))
                desAF = temp.Substring(pF(3), pF(4) - pF(3))
                desA = temp.Substring(pF(4), pF(5) - pF(4))
                desAA = temp.Substring(pF(5), pF(6) - pF(5))
                ecn = temp.Substring(pF(6), pF(7) - pF(6))
                dnf = temp.Substring(pF(7), pF(8) - pF(7))
                repDNF = temp.Substring(pF(8), pF(9) - pF(8))
                repASM = temp.Substring(pF(9), temp.Length - pF(9))
                sw.WriteLine(name & comp & desF & desAF & desA & desAA & ecn & dnf & repDNF & repASM & "CREATED_DATE")
                sw.WriteLine(sa.ReadLine())
                '-----------------------------------------------------------------------      
                'End Using
                '------------------------------------------------------------------------------------------
                ' This opens the first file for reading, you can't write the headers until you've done this
                ' and you have to take into account the two lines you attempt to read above 
                'i.e. you must read and write them before the loop reads the data lines
                'So you need to move these two lines to before the block that reads the header lines. 
                'Also get rid of the Using and End Using above.
                '------------------------------------------------------------------------------------------ 
                'Dim fi1 As FileInfo = datFiles(0)
                'Using sa As StreamReader = New StreamReader(fi1.FullName, System.Text.Encoding.Default)
                '------------------------------------------------------------------------------------------  
                While sa.Peek() >= 0
                    temp = sa.ReadLine()
                    name = temp.Substring(0, pF(1))
                    comp = temp.Substring(pF(1), pF(2) - pF(1))
                    desF = temp.Substring(pF(2), pF(3) - pF(2))
                    desAF = temp.Substring(pF(3), pF(4) - pF(3))
                    desA = temp.Substring(pF(4), pF(5) - pF(4))
                    desAA = temp.Substring(pF(5), pF(6) - pF(5))
                    ecn = temp.Substring(pF(6), pF(7) - pF(6))
                    dnf = temp.Substring(pF(7), pF(8) - pF(7))
                    repDNF = temp.Substring(pF(8), pF(9) - pF(8))
                    repASM = temp.Substring(pF(9), temp.Length - pF(9))
                    sw.WriteLine(name & comp & desF & desAF & desA & desAA & ecn & dnf & repDNF & repASM & Created)
                End While
            End Using
            ' Read and write subsequent files excluding headers      
            For i As Integer = 1 To datFiles.Length() - 1
                fi1 = datFiles(i)
                Using sa As StreamReader = New StreamReader(fi1.FullName, System.Text.Encoding.Default)
                    'read input line    
                    While sa.Peek() >= 0
                        temp = sa.ReadLine()
                        name = temp.Substring(0, pF(1))
                        comp = temp.Substring(pF(1), pF(2) - pF(1))
                        desF = temp.Substring(pF(2), pF(3) - pF(2))
                        desAF = temp.Substring(pF(3), pF(4) - pF(3))
                        desA = temp.Substring(pF(4), pF(5) - pF(4))
                        desAA = temp.Substring(pF(5), pF(6) - pF(5))
                        ecn = temp.Substring(pF(6), pF(7) - pF(6))
                        dnf = temp.Substring(pF(7), pF(8) - pF(7))
                        repDNF = temp.Substring(pF(8), pF(9) - pF(8))
                        repASM = temp.Substring(pF(9), temp.Length - pF(9))
                        '-------------------------------------------------------------------------
                        ' Is this test right? It means the second line in the file will be written
                        ' out. But will only be ------------------------------------ line.
                        '------------------------------------------------------------------------- 
                        If name.Contains("Nom du Modélé") Then
                            ' skip header line - do nothing      
                        ElseIf name.Contains("------") Then
                        Else
                            'write output line    
                            sw.WriteLine(name & comp & desF & desAF & desA & desAA & ecn & dnf & repDNF & repASM & Created)
                        End If
                    End While
                End Using
            Next i
        End Using
        '------------------------------------------------------------
        'Where did the End Sub go to? Is there more code after this?
    End Sub


modified on Wednesday, May 6, 2009 3:35 AM

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 
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 

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.