Site Wide Message: (current site time 9/9/2010 8:17:00 PM EDT)
- We want your input! One of our sponsors wants to know your opinion about development related issues. Click here to tell us what you think.
- Are you an emerging/young developer (aged 18-30)? If so, would you like the chance to affect future developer tools and products?
If so, then click here to give your feedback. |
'Ask the .Net Pros Discussion Forum
You are in:
Discussion Home | standards
| Logical Error: Trying to copy specific statements from a txt file and write it to another
Logical Error: Trying to copy specific statements from a txt file and write it to another
|
|
Author:
medoampir_mj (163.121.195.90) on 1/11/2009 8:49:32 AM
|
|
Message: |
Ok....... I wrote this function to read the client name from the "source file" and search for it in the "remarks file" and if it finds a match it writes the line from the "source file" including the remarks from the "remarks file" in a new txt file named "result. CSV" when i split the line in the remarks file the remark is supposed to be in array(5) and i need to copy it to the same place in the new file.
Well the problem is that I don't get the results I expect... May be there is other hundreds of ways to write these function But I need to solve it this way....] You know "cleaning the floor with the tooth brush.....
Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim line As String Dim remarksline As String Dim thewholefile As String
Dim sourcefilereader As New System.IO.StreamReader("C:\Documents and Settings\Administrator\My Documents\source.csv") Dim oldremarksreader As New System.IO.StreamReader("C:\Documents and Settings\Administrator\My Documents\old.csv") Dim resultswriter As New System.IO.StreamWriter("C:\Documents and Settings\Administrator\My Documents\result.csv")
Do While sourcefilereader.Peek() <> -1 'start reading from the source file line = sourcefilereader.ReadLine() 'reading a line from the source file Dim sourcelineary() As String sourcelineary = line.Split(";") 'spliting the line to elements in an array Do While oldremarksreader.Peek() <> -1 'go to read from the remarks file remarksline = oldremarksreader.ReadLine() 'read a line from remarks file Dim remarkslinearay() As String remarkslinearay = remarksline.Split(";") 'split the line from the remarks file to elements in another array ReDim Preserve remarkslinearay(5) If remarkslinearay(0) = sourcelineary(0) Then 'check if client name in source file is the same in the remarks file sourcelineary(5) = remarkslinearay(5) 'if it is then copy the remark from the remarks file to the source file Exit Do Else sourcelineary(5) = "" End If Loop Dim updatedline As String updatedline = String.Join(";", sourcelineary) thewholefile = thewholefile & updatedline & vbNewLine Loop
resultswriter.WriteLine(thewholefile) sourcefilereader.Close() oldremarksreader.Close() resultswriter.Close() End Sub End Class
Thanks......
|
To reply, please login using the link on the upper left hand corner of the screen.
|
|