Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: TheMinistered on November 29, 2003, 10:32 PM

Title: Running in IDE or NOT?
Post by: TheMinistered on November 29, 2003, 10:32 PM
I have two methods of determining wether or not the application is running in IDE or not, and please feel free to post your own methods.  Here they are:


Function IsIDE() As Boolean
   On Error Goto IDE
   
   Debug.Print 1 / 0
   IsIDE = FALSE
   Exit Function

IDE:
   IsIDE = TRUE
   Exit Function
End Function


This function uses the known fact that the Debug.Print statement will not be executed in a compiled program, thus the Divide by Zero error is not triggered.  In conclusion, it's short and to the point.

However, it has one small drawback, sometimes the programmer may want to run a program in the IDE with the Break on ALL errors option.  The error will obviously be triggered when a call to this function is made.


Function IsIDE() As Boolean
   IsIDE = (App.EXEName = App.Title)
End Function


This function is yet another simple but effective method of testing if the program is in the IDE or NOT, and it avoids using error traps!

However, it requires that the programmer makes sure he compiles to an EXE name that is different from that of the Project name.
Title: Re:Running in IDE or NOT?
Post by: iago on November 29, 2003, 10:37 PM
hmm, in c/c++ you can do this:
#ifdef DEBUG
// we're in ide
#else
// we aren't
#endif

There might be a similar predefined variable in VB?  


And VB actually lets you compile a program that has an obvoius 1/0 in it?  Most compilers won't even let you try!
Title: Re:Running in IDE or NOT?
Post by: Skywing on November 29, 2003, 11:39 PM
Quote from: iago on November 29, 2003, 10:37 PM
hmm, in c/c++ you can do this:
#ifdef DEBUG
// we're in ide
#else
// we aren't
#endif

There might be a similar predefined variable in VB?  


And VB actually lets you compile a program that has an obvoius 1/0 in it?  Most compilers won't even let you try!

Actually, it's

#ifndef NDEBUG
/* debug build */
#endif

This is unrelated to actually having a debugger attached.
Title: Re:Running in IDE or NOT?
Post by: iago on November 30, 2003, 07:40 AM
That's true, but generally you'll have a debug build well testing and a release bulid otherwise.
Title: Re:Running in IDE or NOT?
Post by: Eibro on December 01, 2003, 01:52 PM
There's also IsDebuggerPresent() (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/isdebuggerpresent.asp) for Win32.