Hello, I am reading a simple CSV text file into an array and trying to make a table that looks like:
Col 1 Col 2 Col 3 Total
Row 1 …….. …….. ……… ……..
Row2 …….. …….. ……… ……..
Total …….. …….. ……… ……..
The problem is I cannot figure out how to read the file into the array correctly.
My text file looks like:
1,2,3
4,5,6
Here is my code:
Module Module1
Sub Main()
Dim infile As IO.StreamReader = IO.File.OpenText("numbers.txt")
Dim rows As Integer
Dim cols As Integer
Dim array(3, 2) As Integer
Do While infile.Peek <> -1
Dim line() As String = infile.ReadLine.Split(","c)
For rows = 0 To 2
For cols = 0 To 1
array(rows, cols) = line(rows)
Next
Next
Loop
For i As Integer = 0 To 2
For d As Integer = 0 To 1
Console.Write(array(i, d))
Next
Next
End Sub
End Module
My output currently is 445566. Is the way I split the numbers wrong? Any suggestions or solutions?