1. Computing

Chapter 12 - Text Files and String Processing

From , former About.com Guide

9 of 10

Checking out CSV Files in an Excel Spreadsheet

The result of saving the Excel spreadsheet can be viewed in Notepad to see what has actually been saved.

While we're on this subject, keep in mind that the simple utility Notepad is one of the most valuable tools in a developer's kit - especially for string or character information. Notepad (or WordPad, for very large files that Notepad won't read) is the way to find out just exactly what is in a file, text, formatted, or otherwise. We're using it exactly that way now. It's not transparently clear what Excel actually did save in the file Book1.csv, so we opened it in Notepad to find out!

The program to read the CSV file we created using Excel is actually pretty simple.

~~~~~~~~~~~~~~~~~~~~~~~~~
Dim AboutVar As String
Dim i As Integer
FileOpen(1, "Book1.csv", OpenMode.Input)
For i = 1 To 3
  Input(1, AboutVar)
  ' Debug to see what was read
  Debug.WriteLine(AboutVar)
Next i
~~~~~~~~~~~~~~~~~~~~~~~~~

When the program is executed, you get ...

~~~~~~~~~~~~~~~~~~~~~~~~~
About Visual Basic
~~~~~~~~~~~~~~~~~~~~~~~~~

... in the Output window.

You can write CSV files in VB.NET just as easily:

~~~~~~~~~~~~~~~~~~~~~~~~~
FileOpen(1, "testfile.txt", OpenMode.Output)
Write(1, "About")
Write(1, "Visual")
Write(1, "Basic")
FileClose(1)
~~~~~~~~~~~~~~~~~~~~~~~~~

©2013 About.com. All rights reserved.