Object reference not set to an instance of an object

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

i keep getting this error(see title) with this code, can somebody please
explain to me as to why i am getting these error's:
(albumpath and album ar declared else where)

Dim line, fotoslocation() As String
Dim num As Integer = 0
FileOpen(1, albumpath & album, OpenMode.Input)
While Not EOF(1)
line = LineInput(1)
fotoslocation(num) = line
num += 1
End While
FileClose(1)
 
angus said:
i keep getting this error(see title) with this code, can somebody please
explain to me as to why i am getting these error's:
(albumpath and album ar declared else where)

Dim line, fotoslocation() As String

\\\
Imports System.Collections.Specialized
..
..
..
Dim Line As String
Dim Lines As New StringCollection()
///
Dim num As Integer = 0
FileOpen(1, albumpath & album, OpenMode.Input)
While Not EOF(1)
line = LineInput(1)
fotoslocation(num) = line

Replace the line above with this one:

\\\
Lines.Add(Line)
///
num += 1
End While
FileClose(1)

You are getting the error because you never dimension the 'fotoslocation'
array and thus never assign an array reference to the array variable.
However, as it's hard to determine the number of lines in the file
beforehand I suggest to use a dynamic collection like the 'StringCollection'
instead of the array as shown above.
 
Back
Top