PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
How to know if code has been Compiled? (Solved)-VBForums
Results 1 to 9 of 9

Thread: How to know if code has been Compiled? (Solved)

  1. #1

    Thread Starter
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    Mιxico
    Posts
    1,192

    Resolved How to know if code has been Compiled? (Solved)

    Alright... I have seen this in a couple of sites as a tip which tells you if you are on the VB IDE or you are running the EXE the IDE made.

    Here is the code for that:


    VB Code:
    1. #Const DebugVer = True
    2.  
    3.  #If DebugVer Then
    4.     MsgBox "This is the Debug Version Please Report any Messages"
    5.  #Else
    6.     MsgBox "This is the Final Version :)"
    7.  #End If

    Now... Why doesn't this code work for me?

    I tried running it on a Form and I would always get "This is the Debug Version..." (I mean, after compiling and running the file.exe, of course), then I tried it on a Module and still the same result...

    What am I doing wrong?

    Here are the two locations where I found this "tip":


    First Source Second Source
    Last edited by Tec-Nico; Oct 3rd, 2004 at 01:56 PM.
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,126
    Try this instead.

    VB Code:
    1. Option Explicit
    2.  
    3. ' Flag for debug mode
    4. Private mbDebugMode As Boolean
    5.  
    6.  
    7. ' Set mbDebugMode to true. This happens only
    8. ' if the Debug.Assert call happens. It only
    9. ' happens in the IDE.
    10. Private Function InDebugMode() As Boolean
    11.     mbDebugMode = True
    12.     InDebugMode = True
    13. End Function
    14. ' Set the mbDebugMode flag.
    15. Private Function InIDE()
    16.     ' This will only be done if in the IDE
    17.     Debug.Assert InDebugMode
    18.     If mbDebugMode Then
    19.         InIDE = True
    20.     End If
    21. End Function
    22. Private Sub Form_Load()
    23.     ' See if we are running in the IDE.
    24.    
    25.     If InIDE Then
    26.         MsgBox "In the development environment"
    27.     Else
    28.         MsgBox "In a compiled executable"
    29.     End If
    30. End Sub

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,126
    Here's a really simple way that I found by searching the CodeBank.

    Option Explicit

    VB Code:
    1. Private Function InIDE() As Boolean
    2.  
    3.     On Error Resume Next
    4.  
    5.     Debug.Print 1 / 0
    6.  
    7.     InIDE = (Err.Number <> 0)
    8.  
    9. End Function
    10.  
    11. Private Sub Form_Load()
    12. If InIDE Then
    13.     MsgBox "I'm in IDE"
    14. Else
    15.     MsgBox "I'm compiled"
    16. End If
    17.  
    18. End Sub

  4. #4

    Thread Starter
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    Mιxico
    Posts
    1,192
    Wow! Thank you very much Martin!!!
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  5. #5
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,633

    Re: How to know if code has been Compiled?

    Originally posted by Tec-Nico
    VB Code:
    1. #Const DebugVer = True
    2.  
    3.  #If DebugVer Then
    4.     MsgBox "This is the Debug Version Please Report any Messages"
    5.  #Else
    6.     MsgBox "This is the Final Version :)"
    7.  #End If
    MartinLiss has given you code for checking to see if the app is being run from the IDE or from the EXE. This is the code most developers use.

    However, going back to your original code above, you have this slightly wrong.
    If you have:
    VB Code:
    1. Private Sub Form_Load()
    2.    #If DebugVer Then
    3.       MsgBox "This is the Debug Version Please Report any Messages"
    4.    #Else
    5.       MsgBox "This is the Final Version :)"
    6.    #End If
    7. End Sub
    Then what you do is go to Project/Properties...Then go to the "Make" tab and in the "Conditional Compilation Arguemnts" text box add:
    Code:
    DebugVer = -1
    -1 = True
    0 = False
    And now run your app.
    If you have DebugVer = 0 then when you compile you app the code:
    VB Code:
    1. MsgBox "This is the Debug Version Please Report any Messages"
    WILL NOT BE included in the EXE code. It's completely missed out.

    Woof

  6. #6
    Hyperactive Member AvisSoft's Avatar
    Join Date
    Sep 2002
    Location
    Chandigarh
    Posts
    459
    Whats the use of this code ? Why do you want to know where you are ? I don't understand!
    Tapan Bhanot,
    CEO, Avis Software.
    Website: www.avissoftware.com

  7. #7
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,092
    Originally posted by AvisSoft
    Whats the use of this code ? Why do you want to know where you are ? I don't understand!
    One possible use would be to skip over subclassing while in the IDE. Since a run-time error when subclassing would cause the IDE to crash, it can be a good idea to not subclass when trying to debug something else.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  8. #8
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,633
    On example for the conditions compilation arguments is for say a demo version of your software:
    So you add:
    Code:
    DEMO = -1
    To the compilation arguments. Then in your code you do:
    VB Code:
    1. Public Sub AddRecordToDB()
    2.    #If DEMO Then
    3.        'add code to count number of records
    4.        'if record count > 20 then
    5.        Err.Raise vbObjectError, , "Demo version. Max 20 records allowed"
    6.    #End If
    7.    'Code to add record
    8. End Sub
    So when you compile the DLL, or EXE it's compiled as a demo version or a full version.

    Another example for working out if it's IDE or EXE is you may want to use different file paths etc.

    Woka

  9. #9
    Fanatic Member BrianHawley's Avatar
    Join Date
    Aug 2001
    Location
    Saudi Arabia
    Posts
    796

    Re: How to know if code has been Compiled? (Solved)

    In similar theme, this is a bit of code we use to make sure an app will NOT compile.

    VB Code:
    1. Option  Explicit
    2. #Const TEST = True
    3.  
    4. Sub BadFunction()
    5.   #If TEST Then
    6.      [COLOR=Red]Will not compile if TEST is true[/COLOR]
    7.   #End If
    8. End Sub
    9.  
    10. Sub ExampleFunction()
    11.   #If TEST Then
    12.      'generate fake data for testing
    13.   #Else
    14.      'get real data from the satellite
    15.   #End If
    16.  
    17. End Sub

    Why?

    We set TEST true to test applications in the IDE.

    For instance we may generate fake data instead of getting data from instrumentation that is not connected.

    Obviously it would be a disaster if somebody forgot to set TEST to false, compiled the app and it and sent it to a customer. This way they CAN'T compile it if they forget.
    Brian
    (Fighting with the RightToLeft bugs in VS 2005)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width