Reading in other files
•   VB can read in more than just text files
•   You can also read in CSV files
•   Comma Separated Value files
•   CSV is a way of storing data separated by
    commas
A CSV file opened in Excel
The data one, two, three, four and five would be separated
                by commas in a CSV file
Using VB to read in a CSV file
Dim fileReader As String

fileReader = My.Computer.FileSystem.ReadAllText(" Y:example.csv")

Console.WriteLine(fileReader)

Console.ReadLine()                              Notice the
                                              extension CSV
MEANWHILE IN THE MASTER CHIEF’S KITCHEN . . . .




     HOW AM I
  GONNA SPILT UP
   THAT CSV FILE!
Splitting up CSV’s by Comma
Ideally we want to spilt the CSV file up where the comma
                           exists

                                     Splitting the file
                                       every time a
                                     comma is found
Splitting up CSV’s by Comma
 We can use the split() function to split the CSV by commas




Split(aString, ",")
 The name of the                    Where we want the
string variable we                    split to occur
 want to split up
Splitting up CSV’s by Comma
We need something which is going to be able to hold these
                   separate values
Splitting up CSV’s by Comma
Dim s As String

Dim fileReader As String

fileReader = My.Computer.FileSystem.ReadAllText("example.csv")


s = fileReader
Dim fields As Array                    An Array will hold
                                        the split up CSV
fields = Split(s, ",")
Splitting up CSV’s by Comma
Dim s As String

Dim fileReader As String

fileReader = My.Computer.FileSystem.ReadAllText(" Y:example.csv")

s = fileReader
Dim fields As Array

fields = Split(s, ",")


For i = 0 To UBound(fields)
Console.WriteLine("word " & i & " " & fields(i))

Console.WriteLine("*****************************************")

Next
                               Using a for loop to write
                               the contents of the array
Splitting up CSV’s by Comma
MEANWHILE IN THE MASTER CHIEF’S KITCHEN . . . .




         PHEW!

Splitting up text

  • 2.
    Reading in otherfiles • VB can read in more than just text files • You can also read in CSV files • Comma Separated Value files • CSV is a way of storing data separated by commas
  • 3.
    A CSV fileopened in Excel The data one, two, three, four and five would be separated by commas in a CSV file
  • 4.
    Using VB toread in a CSV file Dim fileReader As String fileReader = My.Computer.FileSystem.ReadAllText(" Y:example.csv") Console.WriteLine(fileReader) Console.ReadLine() Notice the extension CSV
  • 5.
    MEANWHILE IN THEMASTER CHIEF’S KITCHEN . . . . HOW AM I GONNA SPILT UP THAT CSV FILE!
  • 6.
    Splitting up CSV’sby Comma Ideally we want to spilt the CSV file up where the comma exists Splitting the file every time a comma is found
  • 7.
    Splitting up CSV’sby Comma We can use the split() function to split the CSV by commas Split(aString, ",") The name of the Where we want the string variable we split to occur want to split up
  • 8.
    Splitting up CSV’sby Comma We need something which is going to be able to hold these separate values
  • 9.
    Splitting up CSV’sby Comma Dim s As String Dim fileReader As String fileReader = My.Computer.FileSystem.ReadAllText("example.csv") s = fileReader Dim fields As Array An Array will hold the split up CSV fields = Split(s, ",")
  • 10.
    Splitting up CSV’sby Comma Dim s As String Dim fileReader As String fileReader = My.Computer.FileSystem.ReadAllText(" Y:example.csv") s = fileReader Dim fields As Array fields = Split(s, ",") For i = 0 To UBound(fields) Console.WriteLine("word " & i & " " & fields(i)) Console.WriteLine("*****************************************") Next Using a for loop to write the contents of the array
  • 11.
  • 12.
    MEANWHILE IN THEMASTER CHIEF’S KITCHEN . . . . PHEW!