Text File Header

Bigbadborris

Active member
Joined
Aug 21, 2013
Messages
35
Programming Experience
Beginner
Hi

I have text file which contains customer contact info. The first 30 Characters of each line of the file contain the Customer Number and Customer Name. e.g 001 MR FRED BLOGGS
That data that is stored for this customer ( i.e call logs etc ) are to be stored in an individual text files, with the file name based on the customer number e.g 001.txt.
I have over 2000 customer records. I have been able to create the separate txt files. But I would like to put the customer name and number as the first line of there textfile.

I have had to attach a text file with the code that I have because for some reason it becomes unreadable when pasting between code tags

For some reason this puts the first customer name in all the text files.

Can anyone help

Many Thanks
 

Attachments

  • Code.txt
    1.4 KB · Views: 31
In your Do loop, the very first line calls ReadToEnd on your StreamReader. That means that the Do loop will iterate only once because EndOfStream will be True as soon as that first line is executed the very first time. That means that Strline3 is set only once, so you're going to be using that same value every time. The code as is doesn't really make sense. This is what it should look like:
For Each line In File.ReadLines(inputFilePath)
    'line is the current line from the input file.
    'Use it to get the data for the current customer.

    Using writer As New StreamWriter(outputFilePath)
        'Write the customer details.
        'Write the rest of the customer data.
    End Using
Next
By the way, I posted that code snippet like this:[xcode=vb]code goes here[/xcode]

Also, it annoys the hell out of me when people copy code and they trim the whitespace from the beginning of the first line without doing so for any other line. When you copy code, either trim the whitespace off every line or none. You can do the latter by holding down Alt as you drag, allowing you to select a block with a vertical left edge anywhere, not just at the start of each line. Doing the former shouldn't need any instruction.
 
In your Do loop, the very first line calls ReadToEnd on your StreamReader. That means that the Do loop will iterate only once because EndOfStream will be True as soon as that first line is executed the very first time. That means that Strline3 is set only once, so you're going to be using that same value every time. The code as is doesn't really make sense. This is what it should look like:
For Each line In File.ReadLines(inputFilePath)
    'line is the current line from the input file.
    'Use it to get the data for the current customer.

    Using writer As New StreamWriter(outputFilePath)
        'Write the customer details.
        'Write the rest of the customer data.
    End Using
Next
By the way, I posted that code snippet like this:[xcode=vb]code goes here[/xcode]

Also, it annoys the hell out of me when people copy code and they trim the whitespace from the beginning of the first line without doing so for any other line. When you copy code, either trim the whitespace off every line or none. You can do the latter by holding down Alt as you drag, allowing you to select a block with a vertical left edge anywhere, not just at the start of each line. Doing the former shouldn't need any instruction.

That's Great Thank you your help

My Apologies for the errors in my previous post


Many thanks again.
 
Back
Top