exit(0) function in vc++.net
-
hello all... i have a parent form and some child forms.. In child form(both in .h and .cpp files), if i want to exit from a particular function or procedure or event, i used exit(0) function.. it works fine.. But when i use the same function in parent form, it closes the application instead of exiting just from the particular function.. why? pls explain... Salai
-
hello all... i have a parent form and some child forms.. In child form(both in .h and .cpp files), if i want to exit from a particular function or procedure or event, i used exit(0) function.. it works fine.. But when i use the same function in parent form, it closes the application instead of exiting just from the particular function.. why? pls explain... Salai
-
if you want to quit a function, use the
return
keyword...
TOXCCT >>> GEII power
[toxcct][VisualCalc]Hi..thanks for yr reply... But thats not a function.. its an event.. check this code.. private: System::Void mnuimport_Click(System::Object * sender, System::EventArgs * e) { if (MinmaxFlag==false) { MessageBox(0,"Configuartion file is not set. Please import it.","Configuration",MB_OK); exit(0); } else if (RangesFlag== false) { MessageBox(0,"Data Ranges file is not set. Please set it.","Data Ranges",MB_OK); exit(0); } OpenFileDialog *openFileDialog1 = new OpenFileDialog(); Stream *str; openFileDialog1->InitialDirectory = "c:\\Neural Net\\" ; openFileDialog1->Filter = "data files (*.data)|*.data|All files (*.*)|*.*" ; openFileDialog1->FilterIndex = 2 ; openFileDialog1->RestoreDirectory = true ; .......... } Salai
-
Hi..thanks for yr reply... But thats not a function.. its an event.. check this code.. private: System::Void mnuimport_Click(System::Object * sender, System::EventArgs * e) { if (MinmaxFlag==false) { MessageBox(0,"Configuartion file is not set. Please import it.","Configuration",MB_OK); exit(0); } else if (RangesFlag== false) { MessageBox(0,"Data Ranges file is not set. Please set it.","Data Ranges",MB_OK); exit(0); } OpenFileDialog *openFileDialog1 = new OpenFileDialog(); Stream *str; openFileDialog1->InitialDirectory = "c:\\Neural Net\\" ; openFileDialog1->Filter = "data files (*.data)|*.data|All files (*.*)|*.*" ; openFileDialog1->FilterIndex = 2 ; openFileDialog1->RestoreDirectory = true ; .......... } Salai
in a C++ point of view, even if it is an "event", you put the code that will be executed when the event raises inside a function, don't you ? so, even if the event handler (yeah, the function) has a void returning type, you can type where you want to exit the code line below :
return;
you say to the compiler to give the hand to the procedure that called this handler, without returning value... isn't it what you want ?
TOXCCT >>> GEII power
[toxcct][VisualCalc] -
hello all... i have a parent form and some child forms.. In child form(both in .h and .cpp files), if i want to exit from a particular function or procedure or event, i used exit(0) function.. it works fine.. But when i use the same function in parent form, it closes the application instead of exiting just from the particular function.. why? pls explain... Salai
salaikumar wrote:
But when i use the same function in parent form, it closes the application...
Which is exactly what
exit()
is supposed to do (i.e., it terminates the calling process). The return statement, on the other hand, terminates execution of the function in which it appears and returns control (and the value of expression if given) to the calling function. See the difference?
"Take only what you need and leave the land as you found it." - Native American Proverb