0

I'm writing a script for a class and I am running into a problem where I am getting the error

"System.NullReferenceException: 'Object variable or With block variable not set.'

Here is the code that I am using to try and get it to write

Private Sub SaveToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ToolStripMenuItem6.Click


    If SaveDialog.ShowDialog(txtScanNumber.Text) = DialogResult.OK Then

            Dim fileName As String = SaveDialog.FileName

            Dim sFile As New System.IO.FileStream(fileName,
            System.IO.FileMode.Create)

            Dim wFile As New System.IO.StreamWriter(sFile)

            wFile.Write(txtScanNumber.Text)

            wFile.Close()
           End If

    End Sub

I expect it to save to local drive and be able to recall it with a load function that I will add later.

sedders123
  • 791
  • 1
  • 9
  • 19
  • The lines which wrap may be causing problems. If I remember correctly you can't just arbitrarily wrap a line in VB like you can in more C-like languages. – David Jan 08 '19 at 19:40
  • Possible duplicate of [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Enigmativity Jan 09 '19 at 08:21
  • ShowDialog() does not take a string argument. Delete the argument or use `Me`. Favor Option Strict On at the top of the source code file so the compiler can tell you that you are doing it wrong. – Hans Passant Jan 09 '19 at 10:30

0 Answers0