an OpenFileDialog problem

G

Guest

Hello
I am trying to open a text file, I use this code :

private: void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
Stream^ myStream;
OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog;
openFileDialog1->InitialDirectory = "c:\\";
openFileDialog1->Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
openFileDialog1->FilterIndex = 2;
openFileDialog1->RestoreDirectory = true;
if ( openFileDialog1->ShowDialog() == ::DialogResult::OK )
{
if ( (myStream = openFileDialog1->OpenFile()) != nullptr )
{
myStream->Close();
}
}
}

The problem is that I obtain this error messages :

error C3083: 'DialogResult': the symbol to the left of a '::' must be a type
error C2039: 'OK' : is not a member of '`global namespace''
error C2065: 'OK' : undeclared identifier

All the errors are in this line :

if ( openFileDialog1->ShowDialog() == ::DialogResult::OK )

Please help me
Thanks
 
J

Jochen Kalmbach [MVP]

Hi tlemcenvisit!
All the errors are in this line :

if ( openFileDialog1->ShowDialog() == ::DialogResult::OK )

If a symbols starts with "::" it is assumed that it is in the
global-namespace!
So please remove the "::" at the beginning of the "DialogResult::OK"!

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 
G

Guest

I have doing it
Now I have two error messages:
e:\projets visual studio\rien\rien\Form1.h(121) : error C2039: 'OK' : is not
a member of 'System::Windows::Forms::Form::DialogResult'
e:\projets visual studio\rien\rien\Form1.h(24) : see declaration of
'System::Windows::Forms::Form::DialogResult'
e:\projets visual studio\rien\rien\Form1.h(121) : error C2065: 'OK' :
undeclared identifier

Please help me
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top