Before XML, simply separating values by a comma or other delimiter was a very popular way to structure data in files. To handle this case, the Microsoft.VisualBasic.FileSystem namespace also provides the Input function. The code to do that also looks a lot like VB6:
FileName = "CSVFile.txt"
FileOpen(FileNumber, FileName, OpenMode.Input)
Do Until EOF(FileNumber)
Input(FileNumber, StringIn)
Console.WriteLine(StringIn)
Loop
FileClose(FileNumber)
If CSVFile.txt looks like this:
100,200,300
111,222,333
444,555,666,7777
Then you get this in the Output window:
100
200
300
111
222
333
444
555
666
7777
InputString lets you read an arbitrary number of characters at one time. Usually, you will read one character at a time because it's difficult to make sure that you don't hit an EOF Exception error since line endings (usually CRLF - two characters) are read just like regular characters. The CSV file above can be read with this code, however:
FileName = "CSVFile.txt"
FileOpen(FileNumber, FileName, OpenMode.Input)
While Not EOF(FileNumber)
Console.WriteLine(InputString(1, 21))
End While
FileClose(FileNumber)
Note that the result in the Output window looks a little strange. That's because the CRLF characters just show up as new lines again.
100,200,300
111,222,
333
444,555,666,7777
There's a better way to process CSV files later in the article!
FileSystem - The recommended way to go!
Microsoft's recommendation is to use the My.Computer.FileSystem for anything like this. The code example that reads our test Win.Ini file shows how simple it is!
FileName = "Win.Ini"
Console.WriteLine( _
My.Computer.FileSystem.ReadAllText(FileName))
And there are a grundle of other methods that can do just about anything you can think of to a file. If you process simple files, this is the way to do it in VB.NET. It's so simple that there's really not that much to explain. So ... moving on ...

