I am trying to make a SaveFileDialog, I've never made one before so I was trying to. I'm not sure where I'm going wrong, I know that theres streaming involved and stuff like that but I'm getting errors.
Heres my code:
#pragma
once
namespace
Save { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::IO; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; using namespace System::Runtime::Serialization; using namespace System::Runtime::Serialization::Formatters::Binary; /// <summary> /// Summary for Form1 /// /// WARNING: If you change the name of this class, you will need to change the /// 'Resource File Name' property for the managed resource compiler tool /// associated with all .resx files this class depends on. Otherwise, /// the designers will not be able to interact properly with localized /// resources associated with this form. /// </summary> public ref class Form1 : public System::Windows::Forms::Form{
public:Form1(
void){
InitializeComponent();
// //TODO: Add the constructor code here //}
protected: /// <summary> /// Clean up any resources being used. /// </summary>~Form1()
{
if (components){
delete components;}
}
private: System::Windows::Forms::Button^ button1; protected: private: System::Windows::Forms::SaveFileDialog^ saveFileDialog1; private: System::Windows::Forms::RichTextBox^ richTextBox1;private: /// <summary> /// Required designer variable. /// </summary>
System::ComponentModel::Container ^components;
#pragma
region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> void InitializeComponent(void){
this->button1 = (gcnew System::Windows::Forms::Button()); this->saveFileDialog1 = (gcnew System::Windows::Forms::SaveFileDialog()); this->richTextBox1 = (gcnew System::Windows::Forms::RichTextBox()); this->SuspendLayout(); // // button1 // this->button1->Location = System::Drawing::Point(13, 13); this->button1->Name = L"button1"; this->button1->Size = System::Drawing::Size(75, 23); this->button1->TabIndex = 0; this->button1->Text = L"button1"; this->button1->UseVisualStyleBackColor = true; this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click); // // richTextBox1 // this->richTextBox1->Location = System::Drawing::Point(89, 78); this->richTextBox1->Name = L"richTextBox1"; this->richTextBox1->Size = System::Drawing::Size(100, 96); this->richTextBox1->TabIndex = 1; this->richTextBox1->Text = L""; // // Form1 // this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->ClientSize = System::Drawing::Size(292, 266); this->Controls->Add(this->richTextBox1); this->Controls->Add(this->button1); this->Name = L"Form1"; this->Text = L"Form1"; this->ResumeLayout(false);}
#pragma
endregion private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {saveFileDialog1->DefaultExt =
"*.rtf";saveFileDialog1->FileName =
"Untitled.rtf";saveFileDialog1->Filter =
"Rich Text Format (.rtf)|.rtf";saveFileDialog1->Title =
"Save File";saveFileDialog1->ShowDialog();
DialogResult::get();
Save_Document(saveFileDialog1->FileName());
}
private: System::Void Save_Document(string fileName) {Stream s = File::Open(fileName, FileMode::Create);
BinaryFormatter b =
gcnew BinaryFormatter();Stream::Close();
};
}
Here are my errors:
------ Build started: Project: Save, Configuration: Debug Win32 ------
Compiling...
Save.cpp
c:\documents and settings\removed\my documents\visual studio 2005\projects\save\save\Form1.h(113) : error C2061: syntax error : identifier 'string'
.\Save.cpp(6) : error C2143: syntax error : missing ';' before 'using'
c:\documents and settings\removed\my documents\visual studio 2005\projects\save\save\Form1.h(28) : error C2059: syntax error : 'inline function header'
c:\documents and settings\removed\my documents\visual studio 2005\projects\save\save\Form1.h(28) : error C2143: syntax error : missing ';' before '{'
c:\documents and settings\removed\my documents\visual studio 2005\projects\save\save\Form1.h(28) : error C2447: '{' : missing function header (old-style formal list )
c:\documents and settings\removed\my documents\visual studio 2005\projects\save\save\Form1.h(110) : error C2064: term does not evaluate to a function taking 0 arguments
c:\documents and settings\removed\my documents\visual studio 2005\projects\save\save\Form1.h(110) : error C2660: 'Save::Form1::Save_Document' : function does not take 1 arguments
c:\documents and settings\removed\my documents\visual studio 2005\projects\save\save\Form1.h(114) : error C3622: 'System::IO::Stream': a class declared as 'abstract' cannot be instantiated
c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll : see declaration of 'System::IO::Stream'
c:\documents and settings\removed\my documents\visual studio 2005\projects\save\save\Form1.h(114) : error C2065: 'fileName' : undeclared identifier
c:\documents and settings\removed\my documents\visual studio 2005\projects\save\save\Form1.h(114) : error C3767: 'System::IO::Stream::Stream': candidate function(s) not accessible
c:\documents and settings\removed\my documents\visual studio 2005\projects\save\save\Form1.h(115) : error C3673: 'System::Runtime::Serialization::Formatters::Binary::BinaryFormatter' : class does not have a copy-constructor
c:\documents and settings\removed\my documents\visual studio 2005\projects\save\save\Form1.h(116) : error C2352: 'System::IO::Stream::Close' : illegal call of non-static member function
c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll : see declaration of 'System::IO::Stream::Close'
.\Save.cpp(6) : error C2059: syntax error : ';'
.\Save.cpp(19) : fatal error C1075: end of file found before the left brace '{' at 'c:\documents and settings\removed\my documents\visual studio 2005\projects\save\save\Form1.h(4)' was matched
Build log was saved at "file://c:\Documents and Settings\removed\My Documents\Visual Studio 2005\Projects\Save\Save\Debug\BuildLog.htm"
Save - 14 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

SaveFileDialog
gjutras
This line:
Save_Document(saveFileDialog1->FileName());
John A Grandy
Like I said, there's a lot more wrong than that, I just fixed a few things that I could find with the project I created with this code.
What line is giving this error
M. Leary
Nevermind I figured out where I went wrong:
This is what I had:
Save_Document(saveFileDialog1->FileName());
And this is what I should have had:
richTextBox1->SaveFile(saveFileDialog1->FileName);
I actually didn't need the Save_Document portion of the code at all.
BrijeshK
I'm sorry, but this code is full of issues. Where are you getting your info from
Here are some of the things I was able to sort out
private: System::Void Save_Document(System::String ^ fileName) {FileStream^ s = File::Open(fileName, FileMode::Create);
// needs code here to write the streams->Close();
};
Where are you getting your info from I would recommend taking a step back, buying a good book and working through it. You're obviously trying to learn too much in one go, and getting stuck in a lot of areas. Another piece of advice - write a short bit of code, compile it, and when it works, add to it. Most of this code does not compile, you should have been compiling more often so you had one problem to deal with at a time.
Carol Beth
Ok thanks I put your code in and got one error:
------ Build started: Project: Save, Configuration: Debug Win32 ------
Compiling...
Save.cpp
c:\documents and settings\removed\my documents\visual studio 2005\projects\save\save\Form1.h(110) : error C2064: term does not evaluate to a function taking 0 arguments
Build log was saved at "file://c:\Documents and Settings\removed\My Documents\Visual Studio 2005\Projects\Save\Save\Debug\BuildLog.htm"
Save - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
TANWare
As FileName is a property not a member function the syntax should be:
Save_Document(saveFileDialog1->FileName);