Jump to content

[VB6] How to tell if being run from IDE or EXE?


Recommended Posts

Hi, I’ve just got a small question that’s been driving me nuts. I used to do alot of VB6 programming back in “the day” but I haven’t done any in years, and am quite a bit rusty. I now find myself in the unenviable position of having to write a few “small” programs for work.

I would swear up and down that there was a simple way of telling if the program was being run through the IDE or through a compiled exe, but I can’t for the life of me remember what it is, and I just have no luck hitting the right keywords to find it on google.

Does anybody have any easy, or not-so-easy methods they’d be willing to share?

Link to comment
Share on other sites


Of course, wouldn’t you just know it. Not one minute after I ask the question do I find the answer on my own.

Debug.Assert does not get compiled, so all I have to do is:

Dim IsIDE as Boolean
IsIDE=False
Debug.Assert IsIDE=True

And the EXE will never see the Debug command. Or if that syntax isn’t perfect, some such varient of that code will do the trick.

For anyone who might stumble along here through google some distant day, I found this Debug.Assert method here: http://visualbasic.about.com/od/usevb6/l/blfaq0012a.htm

<sigh>Now I feel like a real smeghead, answering my own questions, like I only asked so I could feel smart or something. I know I’ll be back soon enough with another question I couldn’t figure out on my own. Say... how are any of you with SQL?

Link to comment
Share on other sites

Glad you found it. I use something similar.

Private Function devmode() As Boolean
  Dim ltest As Long
  Debug.Assert Not chkmode(ltest)
  devmode = ltest = 1
End Function

Private Function chkmode(ltest As Long) As Boolean
  ltest = 1
End Function

Private Sub Command1_Click()
  If devmode() = True Then
     MsgBox ("Development Mode")
  Else
     MsgBox ("Runtime Mode")
  End If
End Sub

I use it to set paths for development, since app.path returns the vb6 dir. What are you using it for.

sidenote: in VFP you can do this with function version(2). Everything is so much easier in VFP.

Edited by dman
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...