I have the following code that works well when I save the file. However when the save "to dialog box opens with the "save" or "cancel" option.....When I click Cancel I get and exception error here. W.WriteLine(gradesListBox.Items(1).ToString) How would I fix this? I have tried this but don't get anywhere with it.
If result <> Windows.Forms.DialogResult.Cancel Then
Close()
End If
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim result As DialogResult
'Writes txt File to C: Drive
SaveFileDialog1.InitialDirectory = ("C:\")
SaveFileDialog1.FileName = ("Save As...")
SaveFileDialog1.Filter = ("Only Text Files (*.txt)|*.txt")
SaveFileDialog1.ShowDialog()
Dim W As New IO.StreamWriter(SaveFileDialog1.FileName, True) ' writes specified information to save file
W.WriteLine(lblTimeDate.Text & " " & txtJobFileName.Text)
W.WriteLine() 'Writes Blank Line
W.WriteLine()
'Formats Write to save file
W.WriteLine(vbTab & gradesListBox.Items(0).ToString)
W.WriteLine(gradesListBox.Items(1).ToString)
W.WriteLine(gradesListBox.Items(2).ToString)
W.WriteLine(gradesListBox.Items(3).ToString)
W.WriteLine(gradesListBox.Items(4).ToString)
W.WriteLine(gradesListBox.Items(6).ToString)
W.WriteLine(gradesListBox.Items(9).ToString)
W.WriteLine(gradesListBox.Items(7).ToString)
W.WriteLine(gradesListBox.Items(8).ToString)
W.WriteLine(gradesListBox.Items(9).ToString)
W.WriteLine(gradesListBox.Items(10).ToString)
W.WriteLine()
W.WriteLine()