Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleDetermine whether the program is running in the IDE or as a compiled executable by using Debug.Print
Keywordsrun mode, IDE, executable, Debug.Print
CategoriesMiscellany, Software Engineering
 
Execute a Debug.Print statement that generates an error, using an On Error statement to catch the error. In a compiled executable, the Debug.Print statement is removed so the error doesn't occur.
 
Private debug_mode As Boolean

' Set debug_mode.
Private Sub SetDebugMode()
    On Error GoTo InIDE
    Debug.Print 1 / 0
    debug_mode = False
    Exit Sub

InIDE:
    debug_mode = True
End Sub

Private Sub Form_Load()
    ' See whether we're in the IDE.
    SetDebugMode

    ' Tell the user.
    If debug_mode Then
        Label1.Caption = "In the development environment"
    Else
        Label1.Caption = "In a compiled executable"
    End If
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated