VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Am I running in the IDE?

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

Rate Am I running in the IDE?

'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

Download this snippet    Add to My Saved Code

Am I running in the IDE? Comments

No comments have been posted about Am I running in the IDE?. Why not be the first to post a comment about Am I running in the IDE?.

Post your comment

Subject:
Message:
0/1000 characters