Answered by:
Writing an Array to a text file

Question
-
I’m very new to programming so this is probably fairly easy. And forgive me if I'm asking this in the wrong section. Point me to the right one and I will go there.
I am writing a program that will read a text file of results (all numbers) to an array and then perform various mathematical analysis of those numbers. Unfortunately the results text file has random blank spaces that mess up the array. I have managed to set up a routine to remove the blank spaces. How can I write the new results array to a new text file?
Here is my code so far.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Readfile.Click
'Read the file
Dim res1Array As New ArrayList Dim fileReader As System.IO.StreamReaderfileReader =
My.Computer.FileSystem.OpenTextFileReader("C:\resultol.txt") While Not fileReader.EndOfStreamres1Array.Add(fileReader.ReadLine)
End While' remove blanks
Dim a1 As Integer
For a1 = 0 To res1Array.Countres1Array.Remove(
"") Next a1What I would like to do now is write the contents of resArray1 to a file at c:\working.txt
Any help would be appreciated..
Regards
Scott
Wednesday, October 11, 2006 5:09 AM
Answers
-
simply go through each item in the array and write it to the file:
Dim theWriter as new StreamWriter("fileName.txt")
for each currentItem as String in res1Array
theStreamWriter.WriteLine(currentItem)
next
theWriter.Close()
Wednesday, October 11, 2006 5:48 AM
All replies
-
simply go through each item in the array and write it to the file:
Dim theWriter as new StreamWriter("fileName.txt")
for each currentItem as String in res1Array
theStreamWriter.WriteLine(currentItem)
next
theWriter.Close()
Wednesday, October 11, 2006 5:48 AM -
Thanks so much for your help. I will try this out. Will the code work for VB express as well? For that matter is their a lot of diffrence between standard VB and VB express?
Regards
Scott
Friday, October 13, 2006 2:45 AM -
It'll work just fine :-)Friday, October 13, 2006 5:40 AM
-
Thanks ahmedilyas.. Worked fine..Saturday, October 14, 2006 2:05 AM