¿ Object reference not set to an instance of an object. ?

E

eBob.com

I am getting this error (below) and do not understand how or why.
Perhaps part of the problem is that I am not experienced in OO
programming.

" An unhandled exception of type 'System.NullReferenceException'
occurred in GraphPlay2.exe

Additional information: Object reference not set to an instance of an
object."

This occurs in a very short Sub at the statement indicated ...

Private Sub ReadData()

Dim sInFileName As String = "allfiles.csv"
Dim srInFile As System.IO.StreamReader
Dim DebugTBLines() As String 'for setting TextBox Lines
srInFile = System.IO.File.OpenText(sInFileName)

Do
sInBuf = srInFile.ReadLine()
'MessageBox.Show("Record is """ & sInBuf & """")
If sInBuf Is Nothing Then Exit Do
RecordNumber += 1
If RecordNumber >= MaxFiles Then
MessageBox.Show("Too Damn Many Files; Giving Up")
Close()
Else : ParseInput()
DebugTBLines(RecordNumber) =
FileInfo(RecordNumber).Name '<<<< Error Happens Here !!!
End If

Loop
srInFile.Close()
TextBox1.Lines = DebugTBLines
End Sub 'ReadData

The Watch Window proves that RecordNumber has a value, 0, and that
FileInfo(0).Name has a value.

I'll appreciate any help/adivce/pointers you can offer.

Thanks, Bob
 
J

Jay B. Harlow [MVP - Outlook]

Bob,
Dim DebugTBLines() As String 'for setting TextBox Lines
DebugTBLines is nothing, you need to define a size for the array.

I would probably simply initialize it to MaxFiles, as that seems to be your
limit.

Dim DebugTBLines(MaxFiles) As String 'for setting TextBox Lines

This allows DebugTBLines to have MaxFiles + 1 entries as MaxFiles is the
upper bound of the array, with the lower bound being 0.

Hope this helps
Jay
 
E

eBob.com

Jeez, what a dumb question. Sorry for asking it. Thanks for your
help Jay.

Bob
 
J

Jay B. Harlow [MVP - Outlook]

Bob,
I don't consider it a dumb question, as most or all of us do it once or
twice & miss the fact we did...

Just a thought
Jay
 

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