0

'Random_Number_File_Writer.Form1' does not contain a definition for 'saveFileDialog1_FileOk' and no extension method 'saveFileDialog1)_FileOk' accepting a first argument of type 'Random_Number_File_Writer.Form1' could be found (are you missing a using directive or an assembly reference?)

That, is the error message that I am getting. I tried going to my college's lab for assistance, but the person is not familiar with C# and it took us around an hour just to get my line numbers showing (just for reference...) And then I went to my professor and he said he was going to be busy for a while.. So I thought I'd try here as an alternate source of help.

I looked at the questions already on here regarding similar errors, but it still leaves me puzzled as how to correct this one in particular, and as I referenced the code in my textbook as closely as possible, I'm not sure I understand why I'm even getting this error.

Here's the code, and I'm sorry if it's difficult to read. Oh, and I know that this is the part generating the error, because I had it running yesterday, WITHOUT this part. But part of the assignment is having the save as dialog.

try
        {
            //Initial opening point for save file dialogue
            saveFileDialog1.InitialDirectory = @"C:\Users\Heather\Documents\Visual Studio 2010\Projects\Random Number File Writer";
            //Save As popup - Opening the file for writing usage once it's created.
            if(saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                randomNumberFile = File.CreateText(openFileDialog1.FileName);
            }
            else // Popup informing user that the data will not save to a file because they didn't save.
            {
                MessageBox.Show("You elected not to save your data.");
            }

here's the using stuff that didn't format:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO; // Added to be able to use StreamWriter variable type

And here is the code snippet it gives when I double click and it takes me to the Form1.Designer.CS window.

            this.saveFileDialog1.FileOk += new System.ComponentModel.CancelEventHandler(this.saveFileDialog1_FileOk);
Heather T
  • 323
  • 1
  • 10
  • 20
  • You've shown the *body* of the method, but not the method declaration. Presumably it *should* be called `saveFileDialog1_FileOk`... – Jon Skeet Nov 20 '12 at 17:09
  • Is this entirely winforms, or do you have WPF forms? if so, be sure to implement DialogResult.OK from windows.forms because WPF uses an incompatible definition for DialogResult. – Frank Thomas Nov 20 '12 at 17:11
  • I'm sorry Jon I'm not sure what that would do/where it would go. Is that like a variable declaration? – Heather T Nov 20 '12 at 17:13
  • can you post the stacktrace, and the block of code that contains the lines indicated in it? – Frank Thomas Nov 20 '12 at 17:14
  • using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; // Added to be able to use StreamWriter variable type @Frank – Heather T Nov 20 '12 at 17:14
  • Well that didn't format properly. And it won't even compile – Heather T Nov 20 '12 at 17:15
  • When I double click on the error in the error list, this is what it gives me ** this.saveFileDialog1.FileOk += new System.ComponentModel.CancelEventHandler(this.saveFileDialog1_FileOk);** – Heather T Nov 20 '12 at 17:15
  • @user1839549 you can and should edit your question to include that kind of stuff – Sam I am says Reinstate Monica Nov 20 '12 at 17:16
  • Ah. Thank you Sam. I'll do that now so it displays appropriately. I didn't think of that. – Heather T Nov 20 '12 at 17:16

1 Answers1

0

saveFileDialog1_FileOk Looks like it's supposed to be an event handler( a method) so make sure that you have a method like

public void saveFileDialog1_FileOk(object sender, CancelEventArgs e)
{
}

in your Form1 class

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Stupid double click. Putting that (specifically, since I'm not sure how to edit it) gives more errors than the one I already had. :D Hmm. Unless I put it in the wrong place. Let me shift that. – Heather T Nov 20 '12 at 17:29
  • Allright. I'm apparently not the brightest crayon in the box today, but shouldn't (if someone were to hit cancel or click out with the x) the else statement take care of cancellation? – Heather T Nov 20 '12 at 17:29
  • Aha. Had to lose the comma and the a. Now everything jives I think. It at least compiles. Thanks Sam! – Heather T Nov 20 '12 at 17:33