VinceC
Newcomer
Error: Object reference not set...
I am using VB.Net (Standard Ed.), my program opens a dialog window for selection of a text file (containing numbers) and reads it in as a "stream". It then tries to convert the stream from text to double (unsuccessfully). The error that I get is on the line of code below where it happens. Here is my code, can someone help?
Thanks for any help.
I am using VB.Net (Standard Ed.), my program opens a dialog window for selection of a text file (containing numbers) and reads it in as a "stream". It then tries to convert the stream from text to double (unsuccessfully). The error that I get is on the line of code below where it happens. Here is my code, can someone help?
Visual Basic:
'Code from my Form
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim OpenFileDialog1 As New OpenFileDialog()
OpenFileDialog1.InitialDirectory = "c:\"
OpenFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
OpenFileDialog1.FilterIndex = 2
Dim sreader As IO.StreamReader
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
sreader = IO.File.OpenText(OpenFileDialog1.FileName)
CreateArray(sreader)
sreader.Close()
End If
End Sub
End Class
'Code from my Module
Sub CreateArray(ByVal streamM As IO.StreamReader)
Dim x As Integer
Dim q()
Dim z() As Double
Dim Efile As String
Efile = streamM.ReadToEnd
q = Split(Efile, vbCrLf)
For x = 1 To q.Length - 1
z(x) = CDbl(q(x)) 'Error I receive: "Object reference not set to an instance of an object."
Next x
End Sub
Thanks for any help.
Last edited by a moderator: