I am trying to take a text file that has around 7000 lines of data and make a few small edits to it so that the data can be moved to a database. Basically I am trying to take a date/time field that is written as "12/10/09 1158" and make it look like "12/10/09 11:58:00" because the database will not recognize the date/time field if imported under it's current format.
I would like to be able to edit the whole file at once but so far I've had no luck. I have been trying to use the StreamReader & StreamWriter classes to do this but I'm not having any luck. Writing the data to a new file would be a pretty good idea for me as well, that way I can just pull out the fields of data that I need moved to the database table.
If anybody has any tips or code examples to do this I sure would appreciate it.
I am currently trying something like this but it is not writing every record into my new file. I'm only getting around 2200 of the 6800 records.(Please don't laugh too hard, this is my first shot at writing anything) :-(
My output file is coming out with the data that I want but it is just way too short of records. I don't understand why all the records are not being edited and moved over.
Output file data:
12/07/09 20:50:00
12/08/09 07:02:00
12/08/09 08:03:00
12/08/09 08:53:00
12/08/09 08:01:00
Appreciate any help with this.
I would like to be able to edit the whole file at once but so far I've had no luck. I have been trying to use the StreamReader & StreamWriter classes to do this but I'm not having any luck. Writing the data to a new file would be a pretty good idea for me as well, that way I can just pull out the fields of data that I need moved to the database table.
If anybody has any tips or code examples to do this I sure would appreciate it.
I am currently trying something like this but it is not writing every record into my new file. I'm only getting around 2200 of the 6800 records.(Please don't laugh too hard, this is my first shot at writing anything) :-(
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim fileReader As StreamReader
Dim fileWriter As StreamWriter
Dim results As DialogResult
Dim fileout As DialogResult
Dim trans_date As String
results = OpenFileDialog1.ShowDialog
fileout = SaveFileDialog1.ShowDialog
If results = DialogResult.OK Then
fileReader = New StreamReader(OpenFileDialog1.FileName)
fileWriter = New StreamWriter(SaveFileDialog1.FileName, False)
While Not fileReader.EndOfStream
trans_date = fileReader.ReadLine.Substring(461, 8) + fileReader.ReadLine.Substring(469, 3) + ":" + fileReader.ReadLine.Substring(472, 2) + ":00" & ControlChars.NewLine
fileWriter.Write(trans_date)
End While
fileReader.Close()
fileWriter.Close()
Else
End If
End Sub
My output file is coming out with the data that I want but it is just way too short of records. I don't understand why all the records are not being edited and moved over.
Output file data:
12/07/09 20:50:00
12/08/09 07:02:00
12/08/09 08:03:00
12/08/09 08:53:00
12/08/09 08:01:00
Appreciate any help with this.