Read Write Text Files

chwanhun

New member
Joined
Dec 7, 2006
Messages
2
Programming Experience
Beginner
Hello,

I am very new to VB.NET and am having some trouble putting some values from a file in an array and then writing out that info to a different file with some additional text. Here's my logic:

VB.NET:
Dim Filestream AS String
Dim InputFile AS String
Dim splitext(6) As String
InputFile = "c:\testfile.txt)
splitext = splitout(InputFile, ",")
Dim i AS integer
 
For i=0 To spltout.GetUpperBound(0)
If splitout(1) = "E"
Then WriteLine.InputFile(splitout(0), & "very", & splitout(2), & "anotherword" & splitout(3))
Else WriteLine.InputFile(splitout(0), & "None", & splitout(2), & "anotherword" & splitout(3))
Next
End If
I know the syntax isn't correct in the above code, but it is correct in my console application and I get a debug error when it gets to the else statement. The error is something like, "index is not in bounds of array".

I ultimately need to read in the values from a csv file and then write those values plus some additional static text to a different file. I also need the text to write without the delimiter.

Any help is appreciated.
 
Last edited by a moderator:
Index out of bounds means you are trying to use an element of the array that dosen't exist. Looking at your code, I would guess it's where you are referencing splitout(0), 2, and 3.

It's likely that for the splitout array, element 0, 2, or 3, dosen't exist at the time you are trying to use it.
 
2 dimensional array

ok, so I failed to realize that my file should actually be read into a 2-dimensional array. Question: I have to reformat the data in the file and write it out to another file. I then need to insert that data into a database table (not datatable). What is the best way to do that? Read the file into a dataset or an array? Thanks.
 
Back
Top