N
Necromis
The below code is giving me an error of.....
"System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
......in this line........
the yellow error highlight is highlighting the line below. (arrow)
Do
MA = Parse(streamLine)
MyArray(Counter).Acctno = MA(0) <====Highlighted row
Can anyone suggest as to what is causing the problem and a solution?
Or possibly an alternate way of acomplishing what the code is trying
to do. Thanks
Imports System.IO
Imports Microsoft.VisualBasic
Public Class Form1
Structure MyType
Dim Acctno As String
Dim Name As String
Dim expdate As String
Dim cr_line As String
End Structure
Dim MyArray As MyType()
Private Function Parse(ByRef theLine As String) As String()
Dim tempArray() As String
Dim delimiters As Char = (","c)
tempArray = theLine.Split(delimiters)
Return tempArray
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim infile As String
Dim fileLoc As String
fileLoc = "F:\VB Express\"
infile = fileLoc & infileBox.Text
Me.LoadTextFileIntoMyArray(infile)
End Sub
Private Sub LoadTextFileIntoMyArray(ByVal filePath As String)
Dim reader As New StreamReader(filePath, FileMode.Open)
Dim streamLine As String = reader.ReadLine()
Dim MA As String()
Dim Counter As Integer = 0
Do
MA = Parse(streamLine)
MyArray(Counter).Acctno = MA(0)
MyArray(Counter).Name = MA(1)
MyArray(Counter).expdate = MA(2)
MyArray(Counter).cr_line = MA(3)
Counter += 1
Loop While Not theLine Is Nothing
reader.Close()
End Sub
End Class
"System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
......in this line........
the yellow error highlight is highlighting the line below. (arrow)
Do
MA = Parse(streamLine)
MyArray(Counter).Acctno = MA(0) <====Highlighted row
Can anyone suggest as to what is causing the problem and a solution?
Or possibly an alternate way of acomplishing what the code is trying
to do. Thanks
Imports System.IO
Imports Microsoft.VisualBasic
Public Class Form1
Structure MyType
Dim Acctno As String
Dim Name As String
Dim expdate As String
Dim cr_line As String
End Structure
Dim MyArray As MyType()
Private Function Parse(ByRef theLine As String) As String()
Dim tempArray() As String
Dim delimiters As Char = (","c)
tempArray = theLine.Split(delimiters)
Return tempArray
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim infile As String
Dim fileLoc As String
fileLoc = "F:\VB Express\"
infile = fileLoc & infileBox.Text
Me.LoadTextFileIntoMyArray(infile)
End Sub
Private Sub LoadTextFileIntoMyArray(ByVal filePath As String)
Dim reader As New StreamReader(filePath, FileMode.Open)
Dim streamLine As String = reader.ReadLine()
Dim MA As String()
Dim Counter As Integer = 0
Do
MA = Parse(streamLine)
MyArray(Counter).Acctno = MA(0)
MyArray(Counter).Name = MA(1)
MyArray(Counter).expdate = MA(2)
MyArray(Counter).cr_line = MA(3)
Counter += 1
Loop While Not theLine Is Nothing
reader.Close()
End Sub
End Class