I'm new in vb.net programming, and i want to read a 2d array from a file. I searched a lot and i can't figure out how can i do that. There is the input file :
1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1
And here is the code part :
Dim map As Integer(,)
Dim reader As StreamReader
    reader = IO.File.OpenText(folder + "\harta\harta.txt")
    Dim linie As String, i, j As Integer
    For i = 0 To 10
        For j = 0 To 12
            linie = reader.ReadLine()
            map(i, j) = linie.Substring(j, linie.IndexOf(" ")) 'here is my problem'
        Next j
    Next i
    reader.Close()
When i run the code, i get the following error:
An unhandled exception of type 'System.NullReferenceException' occurred in WindowsApplication1.exe
Edit:
I tried another method :
Dim reader As IO.StreamReader
    reader = IO.File.OpenText(folder + "\harta\harta.txt")
    Dim linie As String, i, j As Integer
    For i = 0 To 10
        linie = reader.ReadLine
        Dim parametrii As String() = linie.Split(" ")
        Dim parametru As String
        j = 0
        For Each parametru In parametrii
            map(i, j) = parametru 'i get the same error here'
            j += 1
        Next
    Next i
I really dont know what is wrong.
 
     
     
    