Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't close Visual Foxpro window

Status
Not open for further replies.

dgold

Technical User
Feb 17, 2000
8
0
0
CA
A programmer wrote us a little Visual Foxpro program to dial up our ISP, connect our server via ftp and then upload a small file to our server, then hang up the connection. All of this works fine except than when we attempt to close the Visual Foxpro window, we get the message &quot;Cannot quit Visual Foxpro&quot;. Our users have to use Crtl + Alt + Del 2 or 3 times to end this task. Any better way to close Visual Foxpro windows running in Windows 98? Our programmer is no longer available to help us on this. Thanks.<br>
<br>
Douglas<br>

 
if you have source just add a button on the form with<br>
thisform.release in the click event <p>Steve Bowman<br><a href=mailto:steve.bowman@wayservices.com>steve.bowman@wayservices.com</a><br><a href= > </a><br>
 
As Steve said, &quot;if you have source.&quot; If you don't, you are somewhat out of luck, unless this experiment works:<br>
<br>
When the program finishes, I assume you have a &quot;blank&quot; Visual FoxPro screen (no form visible). Try pressing the ESC key. If it returns you to the Command Window, you can then type QUIT to exit. You *might* be able to wrap this process in another PRG (i.e. calling the main app from another program, then adding CANCEL/QUIT after the call - you might have to fiddle with adding a hotkey to force the CANCEL (ON KEY LABEL F10 CANCEL)).
 
If you have access to the source code, I'd just put in the command ON SHUTDOWN QUIT at the top.<br>

 
How to avoid the Cannot Quit Visual FoxPro message<br>Ever tried to close your application, only to be told you can't? Here's the story.<br>You've developed your application and handed it to the user. Everything is fine. Then you get a phone call. The user tried to close the app, but all that happened was that a message appeared: &quot;Cannot quit Visual FoxPro&quot; (see Figure 1). Why? Because the application is still in an event loop.<br>&nbsp;<br>Figure 1: The dreaded Cannot Quit message<br>Somewhere in the app's controlling logic, you have code that looks like this:<br>DO MainMenu.MPR<br>READ EVENTS<br>Once the program has been put in an event loop (which is what READ EVENTS does), you won't be able to close down until you have exited the event loop. You do that with the CLEAR EVENTS command. You would normally execute CLEAR EVENTS whenever the user signals that they want to close the application – in the Exit command from the File menu, for example.<br>But what if the user tries to close the application by clicking on the Close box in the title bar? Or by shutting down Windows itself while the application is still running? In those cases, the program won't have had an opportunity to execute CLEAR EVENT. The event loop is still active, so the Cannot Quit message appears.<br>To avoid this, use the ON SHUTDOWN command. This works in the same way as VFP’s other &quot;On&quot; commands, such as ON ERROR, in that it specifies an action which is to be taken when a certain event occurs. In this case, the event is any attempt to close the application, by whatever means.<br>So all you have to do is execute ON SHUTDOWN CLEAR EVENTS. You do this near the beginning of the program – in any case before the READ EVENTS. Once you have done that, the user should never again see the Cannot Quit message. When the user hits the Close box in the title bar, the program will execute the ON SHUTDOWN code, which in turn will exit the event loop and pass control to the code following the READ EVENTS. End of problem.<br>Nothing happens<br>Well, not quite. Now try running the app from the VFP development environment. Close the app. Then try to quit Visual FoxPro. It makes no difference whether you use the File Exit command, click on the Close box or type QUIT in the Command Window. The result is the same: nothing happens.<br>Why? Because the ON SHUTDOWN command is still in effect. Instead of closing down, VFP is merely executing a CLEAR EVENTS, which has no effect if you are in the development environment and there is no program running.<br>To avoid this, go back to the app, and add another ON SHUTDOWN command. This time, make it simply ON SHUTDOWN by itself. Put this in the clean-up code, that is, somewhere after the READ EVENTS. The effect will be to cancel the original ON SHUTDOWN.<br>This pair of commands – ON SHUTDOWN CLEAR EVENTS and ON SHUTDOWN by itself – are the minimum you need to close down gracefully. But, depending on how the app is structured, you might need to do more.<br>Cleaning up<br>In our own applications, the File Exit command performs a certain amount of cleaning up before it issues its CLEAR EVENTS. Specifically, it iterates through the collection of open forms (that is, the Forms collection in _SCREEN), closing each form in turn. As it does so, it prompts the user to deal with any unsaved edits. At that point, the user can decide to cancel the shut-down, in which case the exit routine will leave the relevant form open and refrain from clearing the event loop.<br>The application needs to go through this same procedure no matter how the user tries to close down. To achieve this, we put the above processing in a procedure, which we call FileExit. The Exit command on the File menu calls this procedure with a simple DO FileExit. And so does the ON SHUTDOWN command. In other words, instead of executing ON SHUTDOWN CLEAR EVENTS, we execute ON SHUTDOWN DO FileExit. That way, the shut-down procedure is always the same, whatever the user did to initiate it.<br>&nbsp;<br>
 
Not only do you need to add the ON SHUTDOWN statement you also need to add code in QueryUnload method of the form to tell do whatever needs to be done when they click the close (x) in the upper right hand corner of the form.
 
Please give me example for the following :<br>connect to server via ftp and then download file to&nbsp;&nbsp;hard disk, then hang up the connection. <br>
 
Just a thought, but did the programmer build any other means to exit into your program (e.g. a pushbutton or menu entry)?&nbsp;&nbsp;If so, try these instead.<br><br>My experience with FoxPro 2.6 for Windows is that ON SHUTDOWN... is only required in order to exit via the window Control Menu.&nbsp;&nbsp;Without it, exit is still possible if alternative mechanisms have been built in.<br> <p>Andy Blay<br><a href=mailto:a.d.blay@talk21.com>a.d.blay@talk21.com</a><br><a href= > </a><br>
 
Douglas it sounds like you are not a developer.&nbsp;&nbsp;If you contact anyone posting here I am sure they would write you an app.&nbsp;&nbsp;I cannot speak for others but the fee should be nominal.&nbsp;&nbsp;It's a very simple program.&nbsp;&nbsp;You could even use CUTE FTP or other shareware program to handle this.<br><br>John Durbin
 
My apps won't close even though I put an 'on shutdown' command which I copy from the examples that come with Visual FoxPro software. This message appears when the program crashes, such as 'variable not found, 'table has no index', etc. It doesn't matter whether I respond 'yes' or 'cancel' to the dialog box that comes up to the screen. The only choice is to kill it with ctrl-alt-del keys and fix the error(s).<br>I'm fairly new to vfp so I still make a lot of errors in my aplications.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top