Although a plethora of different code examples prevail, this is the
correct method of determining whether the current application execution
is taking place in the Visual Basic IDE (design time) or as an exe
(runtime), by Mathew Curland, VB God.
In
discussing this approach over others (predominantly the Division by 0
error trap), Matt states: After being bitten a couple of times several
years ago, I've always considered a function that expects an error with
On Error Resume Next but no On Error GoTo 0 or Err.Clear to be a bug
waiting to happen, because a calling routine that uses On Error Resume
Next and checks the Err state will get a false error report. |
Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ©1996-2011 VBnet/Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
' applications, but you may not reproduce
' or publish this code on any web site,
' online service, or distribute as source
' on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Function IsInIDE() As Boolean
Dim x As Long
Debug.Assert Not TestIDE(x)
IsInIDE = x = 1
End Function
Private Function TestIDE(x As Long) As Boolean
x = 1
End Function |