Search Tools Links Login

Am I running in the IDE?


The proper way to find out whether your code is running in the IDE or was compiled

Original Author: Ulli

Code

'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

About this post

Posted: 2003-06-01
By: ArchiveBot
Viewed: 97 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.