Detecting If Code Is Running In The VB IDE

It relies on the fact that VB removes Debug.Print statements from the compiled EXE. Use Debug.Print to print something that will cause an error. Divide by zero is simple enough.

Public Function IsCodeCompiled() As Boolean
  On Error GoTo ErrorHandler
  Debug.Print 1 / 0
  IsCodeCompiled = True
  Exit Function
ErrorHandler:
  IsCodeCompiled = False
  Exit Function
End Function

Tip Submitted By: David Hay


Discover more from dotNetTips.com

Subscribe to get the latest posts sent to your email.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.