Compile pragma only in release

Posted on 2004-11-19
Last Modified: 2008-02-20

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.

Question by:eric3333
    LVL 7

    Accepted 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

    Author Comment


    Yes a good idea.
    Will take that.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
    When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now