>Hi Elias,
>the code can work well on my machine.
>this is my code i emulate yr code. in order to test it, i
>put it into a mfc project named as ifstream. the code
>snippet list below.
>#include "stdafx.h"
>#include "ifstream.h"
>#include "ifstreamDlg.h"
>#include <fstream.h>
>class CIfstreamDlg : public CDialog
>{
>.....
> bool success; //for convenience,i treat
> //success as member var
> void mainprogram();
>.....
>};
>void CIfstreamDlg::OnOK()
>{
> mainprogram(); //Calls the function mainprogram.
> //When this process ends, the
> //estimator finishes.
> if(success == FALSE)
> return;
> CDialog::OnOK();
>}
>void CIfstreamDlg::mainprogram()
>{
> ifstream datafile ("c:\\abcde.txt"); //c:\abce.txt
> //doesn't exists
> int abc=0;
> if (!datafile.is_open())
> {
> MessageBox("The file was not opened.\n Please
>retry", "Error message", MB_OK | MB_ICONINFORMATION);
> abc=1; //it is not called
> }
>success = TRUE;
>if (abc==1) success = FALSE;
>}
>although abcde.txt doesn't exist, but datafile will
>create a new file and as a result the messagebox will not
>appear. is the yr m_FileNameFull similar
>to "c:\\abcde.txt" ?
>>-----Original Message-----
>>Justin,
>>Here is some more info about my application. Hopefully
>this will clear
>>up some things:
>>I have the following function which is supposed to call
>the
>>mainprogram() which contains among others the check
>whether the file to
>>be read exists and issues the message box in case that
>it does not.
>>void CDialog1Dlg::OnOK()
>>{
>> extern bool success; //success is false if an
>invalid file is selected
>> mainprogram(); //Calls the function mainprogram.
>> //When this process ends, the
>estimator finishes.
>> if(success == FALSE)
>> return; //if invalid file selected,
>allows user to
>>enter another one
>>CDialog::OnOK();
>>(then it has some other irrelevant code)
>>Following is my main program
>>void CDialog1Dlg::mainprogram()
>>{
>> ifstream datafile (m_FileNameFull); //m_FileNameFull
>was read in the
>>Browse function
>> int abc=0; //to check if the following 'if' loop is
>called
>> if (!datafile.is_open()) //checks to see if file
>opens successfully
>> {
>> MessageBox("The file was not opened.\n Please
>retry", "Error
>>message", MB_OK | MB_ICONINFORMATION);
>> abc=1; //it is not called
>> }
>>extern bool success;
>>success = TRUE;
>>if (abc==1) success = FALSE; //returns FALSE and allows
>user to reenter
>>file (checked above in onOK() function)
>>Hope this helps.
>>Thanks for your interest,
>>Elias
>>>MessageBox need four parameters as below,
>>>MessageBox(0,"The file was not opened.\n Please
>>> retry", "Error message", MB_OK |
>MB_ICONINFORMATION);
>>>I can not reproduce your problem by running the code as
>>>below,
>>>// CASE.cpp : Defines the entry point for the
>application.
>>>//
>>>#include "stdafx.h"
>>>#include "windows.h"
>>>int APIENTRY WinMain(HINSTANCE hInstance,
>>> HINSTANCE hPrevInstance,
>>> LPSTR lpCmdLine,
>>> int nCmdShow)
>>>{
>>> int abc=0; //to check if the following 'if' loop
>>>is called
>>> if (1) //checks to see if file opens
>successfully
>>> {
>>> MessageBox(0,"The file was not opened.\n Please
>>>retry", "Error message", MB_OK | MB_ICONINFORMATION);
>>> abc=1; //it is not called
>>> }
>>> return 0;
>>>}
>>>can you give me more code about yr project? you can
>send
>>>thanks
>>>>-----Original Message-----
>>>>I have a dialog which among others asks for the name
>of
>>>a data file. If
>>>>this file does not exist, then a message box is
>>>displayed using the
>>>>following code:
>>>>int abc=0; //to check if the following 'if' loop is
>>>called
>>>> if (!datafile.is_open()) //checks to see if
>file
>>>opens successfully
>>>> {
>>>> MessageBox("The file was not opened.\n Please
>>>retry", "Error
>>>>message", MB_OK | MB_ICONINFORMATION);
>>>> abc=1; //it is not called
>>>> }
>>>>When I execute the program, and the message box is
>>>displayed, when I
>>>>click on OK, I get a runtime error and the application
>>>shuts down.
>>>>How can I fix this? What I want to do, is return back
>to
>>>my dialog and
>>>>make the necessary corrections.
>>>>Thank you in advance,
>>>>Elias
>>>>.