Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Cancel Unload


Reply
 
Thread Tools Display Modes
  #1  
Old 04-22-2004, 06:05 PM
cooldude4u2no cooldude4u2no is offline
Centurion
 
Join Date: Dec 2003
Location: Arkansas
Posts: 118
Default Cancel Unload


How would you go about canceling a form unload? i have this msgbox appear asking if a user wants to save a file that has Yes No Cancel on it. When the user clicks cancel i dont want the form to unload. How do i go about doing that? thanks.

cooldude4u2no
Reply With Quote
  #2  
Old 04-22-2004, 06:10 PM
webbone's Avatar
webbone webbone is offline
Hydrogen Powered

Administrator
* Expert *
 
Join Date: Jul 2003
Location: Sacramento, CA
Posts: 6,090
Default

You can cancel unloading in the Query_Unload event. See the MSDN page for info: http://msdn.microsoft.com/library/en...ueryunload.asp

If your messagebox is in the Unload event you will need to move it.
__________________
"With the appearance of the AddressOf operator, an entire industry has developed among authors illustrating how to do previously impossible tasks using Visual Basic. Another industry is rapidly developing among consultants helping users who have gotten into trouble attempting these tasks." -Dan Appleman
Reply With Quote
  #3  
Old 04-22-2004, 06:20 PM
Banjo's Avatar
Banjo Banjo is offline
Hell's Angel

Retired Moderator
* Guru *
 
Join Date: Jul 2001
Location: Yorkshire, UK
Posts: 10,394
Default

To actually answer your question, the QueryUnload and Unload events both have a Cancel parameter. Set this to none zero to cancel the unload.

Do pay attention to webbone's link though. The distinction between the two events is important (although more so in MDI apps than SDI).
__________________
A wise one man once said "what you talking about dog breath"
Reply With Quote
  #4  
Old 04-22-2004, 06:25 PM
webbone's Avatar
webbone webbone is offline
Hydrogen Powered

Administrator
* Expert *
 
Join Date: Jul 2003
Location: Sacramento, CA
Posts: 6,090
Default

*L* I learn something new everyday! I've always used QueryUnload and never even noticed that Unload has a cancel as well.
__________________
"With the appearance of the AddressOf operator, an entire industry has developed among authors illustrating how to do previously impossible tasks using Visual Basic. Another industry is rapidly developing among consultants helping users who have gotten into trouble attempting these tasks." -Dan Appleman
Reply With Quote
  #5  
Old 04-22-2004, 06:30 PM
cooldude4u2no cooldude4u2no is offline
Centurion
 
Join Date: Dec 2003
Location: Arkansas
Posts: 118
Default

Quote:
Originally Posted by webbone
You can cancel unloading in the Query_Unload event. See the MSDN page for info: http://msdn.microsoft.com/library/en...ueryunload.asp

If your messagebox is in the Unload event you will need to move it.

Thanks! It worked... One step closer to completing my personal project...woohoo! Thanks again!
Reply With Quote
  #6  
Old 04-22-2004, 06:33 PM
cooldude4u2no cooldude4u2no is offline
Centurion
 
Join Date: Dec 2003
Location: Arkansas
Posts: 118
Default

Ok another Question... How can i cancel the form from unloading when you press the cancel button on commondialog?
Reply With Quote
  #7  
Old 04-22-2004, 06:35 PM
Banjo's Avatar
Banjo Banjo is offline
Hell's Angel

Retired Moderator
* Guru *
 
Join Date: Jul 2001
Location: Yorkshire, UK
Posts: 10,394
Default

Set the CancelError property to true and wrap the call in an error handler.
__________________
A wise one man once said "what you talking about dog breath"
Reply With Quote
  #8  
Old 04-22-2004, 06:42 PM
cooldude4u2no cooldude4u2no is offline
Centurion
 
Join Date: Dec 2003
Location: Arkansas
Posts: 118
Default

Could you give me an example on how? Im clueless...
Reply With Quote
  #9  
Old 04-22-2004, 06:44 PM
Banjo's Avatar
Banjo Banjo is offline
Hell's Angel

Retired Moderator
* Guru *
 
Join Date: Jul 2001
Location: Yorkshire, UK
Posts: 10,394
Default

Code:
cdlg.CancelError = True On Error Resume Next cdlg.ShowOpen If err.Number = 0 Then ' Do Stuff with cdlg.filename Else Cancel = True End If On Error Goto 0
__________________
A wise one man once said "what you talking about dog breath"
Reply With Quote
  #10  
Old 04-22-2004, 06:46 PM
Banjo's Avatar
Banjo Banjo is offline
Hell's Angel

Retired Moderator
* Guru *
 
Join Date: Jul 2001
Location: Yorkshire, UK
Posts: 10,394
Default

Or alternatively:
Code:
cdlg.CancelError = True On Error Goto CancelPressed cdlg.ShowOpen On Error Goto 0 ' Do Stuff with cdlg.filename Exit Sub CancelPressed: Cancel = True End Sub
__________________
A wise one man once said "what you talking about dog breath"
Reply With Quote
  #11  
Old 04-22-2004, 08:31 PM
cooldude4u2no cooldude4u2no is offline
Centurion
 
Join Date: Dec 2003
Location: Arkansas
Posts: 118
Default

Quote:
Originally Posted by Banjo
Or alternatively:
Code:
cdlg.CancelError = True On Error Goto CancelPressed cdlg.ShowOpen On Error Goto 0 ' Do Stuff with cdlg.filename Exit Sub CancelPressed: Cancel = True End Sub
Thanks man! That answered all of my questions...now it should all be smooth sailing...i hope lol...Thanks a ton.

Cooldude4u2no
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Unload vs Nothing fizzled General 5 09-20-2003 08:53 PM
Stumped :\ rpgreligion General 16 03-11-2003 04:14 PM
Form Unload, Show, etc. mikec Word, PowerPoint, Outlook, and Other Office Products 3 11-05-2002 06:11 AM
RuntimeError-365 deepika General 13 04-04-2002 03:07 PM
Someone Help Me With My Message Boxes Please!! Tajiri17 General 12 03-02-2002 11:29 AM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->