|
-
Feb 16th, 2005, 10:17 AM
#1
Thread Starter
Frenzied Member
Better way of Writing this code? (anyone???)
Hi there
I have a function which takes in the data to be written into a file which is specified and it will add it in terms of column
so
Time
1
2
3
4
Then i add another column
Time,Monkeys
1,120
2,200
3,201
4,202
I am using this code...
is there a better way of doing this because I find if i overuse this function, it will throw up an error about index out of range???
VB Code:
Private Function LoadCSV(ByRef arrData As ArrayList, ByRef FileToPutIn As String)
'We want to create another file, so that while it reads one, it dumps the data into the other.
Dim sReader As StreamReader
Dim sWriter As StreamWriter
Dim arrTemp As Array
Dim al As New ArrayList
Dim i As Integer = 0
Dim strtemp As String
Dim fi As New IO.FileInfo(FileToPutIn)
al.Clear()
If fi.Length > 1 Then
sReader = IO.File.OpenText(FileToPutIn)
Do While sReader.Peek <> -1
al.Add(sReader.ReadLine)
Loop
sReader.Close()
IO.File.Delete(FileToPutIn)
sWriter = IO.File.CreateText(FileToPutIn)
For i = 0 To al.Count - 1
sWriter.WriteLine(al(i) & "," & arrData(i))
Next
sWriter.Close()
Else
sWriter = IO.File.CreateText(FileToPutIn)
For i = 0 To arrData.Count - 1
sWriter.WriteLine(arrData(i))
Next
sWriter.Close()
End If
End Function
Last edited by dinosaur_uk; Apr 1st, 2005 at 06:41 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|