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.Assert
Keywordsrun mode, IDE, executable, Debug.Assert
CategoriesMiscellany, Software Engineering
 
Thanks to C. K. Lam.

Use Debug.Assert to run a function that sets the debug value. The Debug.Assert statement is removed from copmiled executables so it only executes when you run in the IDE.

 
' Flag for debug mode
Private bDebugMode As Boolean

' Set bDebugMode to true. This happens only
' if the Debug.Assert call happens. It only
' happens in the IDE.
Private Function InDebugMode() As Boolean
    bDebugMode = True
    InDebugMode = True
End Function

' Set the bDebugMode flag.
Private Sub SetDebugMode()
    ' This will only be done if in the IDE
    Debug.Assert InDebugMode
End Sub

Private Sub Form_Load()
    ' See if we are running in the IDE.
    SetDebugMode

    ' Tell the user.
    If bDebugMode 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