Object reference not set to an instance of an object

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)
 
H

Herfried K. Wagner [MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top