Dim result As DialogResult = OpenFileDialog.ShowDialog() OpenFileDialog.InitialDirectory = "G:\INFO 250\GoldenJohnHW1\GoldenJohnHW1\bin\Debug" ' open specified file if user did not click cancel button If result <> Windows.Forms.DialogResult.Cancel Then ' get specified file name Dim fileName As String = OpenFileDialog.FileName 'load the text file and populate list box with options Dim lineReader As New System.IO.StreamReader(fileName) While (lineReader.Peek <> -1) peekLstBx.Items.Add(lineReader.ReadLine.Split(",")(0)) lineReader.ReadLine() End While End If End Sub
I used to have this bit of code in there but there was a conflict with the .txt file being used more than once at the same time while it was in there.
If CheckValidity(fileName) = True Then output = New StreamWriter(fileName, False) End If
Im also having trouble writing to the file and I'm not sure why. I have an "Append" button that has this code in it
' use streamwriter to write data to file output.Write(vendorNameTxtBx.Text & ControlChars.Tab) output.Write(phoneNumberTxtBx.Text & ControlChars.Tab) output.Write(streetAddress1TxtBx.Text & ControlChars.Tab) output.Write(streetAddress2TxtBx.Text & ControlChars.Tab) output.Write(cityTxtBx.Text & ControlChars.Tab) output.Write(stateTxtBx.Text & ControlChars.Tab) output.Write(zipCodeTxtBx.Text & ControlChars.Tab) output.Write(currentOutstandingBillTxtBx.Text & ControlChars.Tab) output.Write(salesTaxPayableTxtBx.Text & ControlChars.Tab) output.Write(salesYearToDateTxtBx.Text & ControlChars.Tab) output.Write(salesRepresentativeNameTxtBx.Text & ControlChars.Tab) output.WriteLine(commentsTxtBx.Text)
and it comes up with the issue "object reference not set to to an object instance". Any help would be much appreciated.