by ULLI (93 Submissions)
Category: Miscellaneous
Compatability: VB Script
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (6 Votes)
The proper way to find out whether your code is running in the IDE or was compiled
'this code goes into a class named cEnvironment
Option Explicit
Public Enum eEnvironment
EnvironIDE = 1
EnvironCompiled = 2
End Enum
Public Property Get QueryEnvironment() As eEnvironment
QueryEnvironment = EnvironCompiled
Debug.Assert Not SetToIDE(QueryEnvironment)
End Property
Private Function SetToIDE(Env As eEnvironment) As Boolean
Env = EnvironIDE
End Function
'make QueryEnvironment the default property of class cEnvironment
'------------------------------------------
'and then use this anywhere in your code
Private Sub Something()
Dim Environment As New cEnvironment
Print IIf(Environment = EnvironIDE, " I am running in the IDE", _
" Somebody had mercy and compiled me")
' you don't normally print the result, so you might type this...
' If Environment =
' ..and you will see the two possibilities in VB's popup
End Sub