Error setting CSV to display text

  • Thread starter Thread starter llively2
  • Start date Start date
L

llively2

Object reference not set to an instance of an object. pstrfields =
psrdline.Split(pchrDelimiter)

What am I missing here?

Thanks in advance,

Lynn
 
Here is the code:

Dim psrdCurrent As System.IO.StreamReader
Dim pintcount As Integer
Dim psrdline As String
Dim pstrfields() As String

Dim filename As String
filename = "C:\Documents and Settings\Me\My Documents\Visual Studio
Projects\Multicam.csv"
psrdCurrent = New System.IO.StreamReader(filename)
psrdline = psrdCurrent.ReadLine()
Do Until psrdline = Nothing
Dim psrdfile As String
psrdfile = psrdline & CrLf
psrdline = psrdCurrent.ReadLine()
Loop
Dim pchrDelimiter As Char() = {ToChar(",")}
pstrfields = psrdline.Split(pchrDelimiter)
pintcount += 1
TextBox3.Text = pstrfields(6)
psrdCurrent.Close()
 
You're looping until psrdline is equal to Nothing then trying to access
psrdfile.

pstrfields = psrdline.Split(pchrDelimiter)
pintcount += 1
TextBox3.Text = pstrfields(6)

You may also want to put these lines inside the loop unless it was your
intention to split the entire file into one array, then set the
TextBox3.Text once.

John
 
Back
Top