• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 210
  • Last Modified:

Compile pragma only in release

Does a pragma (#const) exist that is true only when working in debug mode (under VB environement) or the reverse ?

Because i need a portion of code to be compiled only when building the release module but not compiled (or not runned) when i am working under VB environement.

1 Solution
This will let you perform opertions based on the value of a boolean that can only get set to true if the IDE is active.
Just call it in formload or you own init routine. Code in question will still be compiled but will not execute if the boolean condition is not met.

'You can check this flag anywhere in your code
Public IsIDE As Boolean
Private Sub Form_Load()
    IsIDE = False
    'This line is only executed if
    'running in the IDE and then
    'returns True
    Debug.Assert CheckIDE
    'Use the IsIDE flag anywhere
    If IsIDE Then
        MsgBox ("Running under IDE")
        MsgBox ("Running as EXE")
    End If
End Sub
Private Function CheckIDE() As Boolean
    'This function will never be executed in an EXE
    IsIDE = True        'set global flag
    'Set CheckIDE or the Debug.Assert will Break
    CheckIDE = True
End Function
eric3333Author Commented:

Yes a good idea.
Will take that.

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now