VBCE.com - The Premier Website For Visual Basic/CE Developers

 

*Dev Corner

Sample Code
Controls
Workarounds
Tips & Tricks
Q & A
Forums

*Goodies
Downloads
Software
Bookstore


*General
Home
What's New
General Info
Misc. Info


*News Worthy
News
Articles
Editorials
KB Articles
Reviews
Awards

*Miscellaneous
Web Links
Partners
Search
Feedback
Advertising

<% On Error Resume Next SiteStats() %>

Sponsors


More...


Quit Your App on Start-up
By mike@vbce.com

    VBCE cannot use a Sub Main procedure for the startup object for the application, therefore the startup object must be a form. If, during the start-up of your application (Form_Load) you decide that the application needs to terminate, you must cannot use the App.End method in the Form_Load event or an application error will result (See Q183420 & Q180520).

    To prevent the error and end the application during start up, you must terminate in the Form_Activate Event (you should tell the user with a message box). We do this by setting a "flag" for us to check at a later time, during the form Activate event.

Option Explicit
Dim
bAppShouldEnd 'Flag for ending app on startup

Private Sub Form_Load()
  On Error Resume Next
  'Simulate an error and set flag
  Err.Raise 7 'Out of Memory
  If Err.Number <> 0 Then
    'An error occurred during form load,
    'so exit the app by setting our flag.

    MsgBox "Cannot start, error: " & _
      Err.Number & " " & Err.Description
    bAppShouldEnd = True
End If
End Sub


Private Sub Form_Activate()
  If bAppShouldEnd Then App.End
End Sub

bug_word.jpg (1504 bytes)
bug_ant_1.gif (13248 bytes)
workaround.jpg (2931 bytes)

 

“When the bugs get tough,
the tough get coding!”

 

VBCE.com is DevX Winner!

Unless otherwise noted, all information on VBCE.com is Copyright 1998 - 2002
Windows, Windows CE, and Visual Basic are trademarks of the Microsoft Corporation.
VBCE.com is not responsible for content on external sites.
Send all feedback to webmaster@vbce.com
Webmasters - feel free to link to
VBCE.com - Premier Website for Visual Basic/CE Development

Buy Books!