Page 1 of 1

How to detect if running code is being run from IDE or not

Posted: Mon Jan 30, 2012 7:45 pm
by SniffTheGlove
Hi,

Does anyone know how to detect if running code is being run from within the IDE or from an exe.

I need to load a prefs file, currently using

Code: Select all

Global CurrentDirectory.s = GetPathPart(ProgramFilename())
to get the path of the app, however it works fine when run from an exe but I need to specify a different prefs file if running from the IDE. Something along the line of

Code: Select all

If RunWithinIDE
    Global CurrentDirectory.s = GetCurrentDirectory()
ELSE
    Global CurrentDirectory.s = GetPathPart(ProgramFilename())
EndIf
can anyone help as I have tried looking for IDE in the search and also the help file but found nothing suitable and I am sure it must of been discussed on this forum in the past but the seach is bring me 1000's of results

Thank you

Re: How to detect if running code is being run from IDE or n

Posted: Mon Jan 30, 2012 8:07 pm
by ts-soft

Code: Select all

CompilerIf #PB_Compiler_Debugger
Global CurrentDirectory.s = GetCurrentDirectory()
CompilerElse
Global CurrentDirectory.s = GetPathPart(ProgramFilename())
CompilerEndIf
or use the option to create the temp exe in sourcedirectory.

Re: How to detect if running code is being run from IDE or n

Posted: Mon Jan 30, 2012 9:53 pm
by SniffTheGlove
ts-soft wrote:

Code: Select all

CompilerIf #PB_Compiler_Debugger
Global CurrentDirectory.s = GetCurrentDirectory()
CompilerElse
Global CurrentDirectory.s = GetPathPart(ProgramFilename())
CompilerEndIf
or use the option to create the temp exe in sourcedirectory.
Thank you very much.

Re: How to detect if running code is being run from IDE or n

Posted: Tue Jan 31, 2012 7:12 am
by skywalk
I use something similar to check for IDE, but also want to know if the exe is 'PureBasic_Compilation0x.exe'.

Code: Select all

Macro IsIDE()
  FindString(GetFilePart(ProgramFilename()),"PureBasic_Compilation")
EndMacro

Re: How to detect if running code is being run from IDE or n

Posted: Tue Jan 31, 2012 12:53 pm
by luis
@skywalk

Nice trick :)

Re: How to detect if running code is being run from IDE or n

Posted: Tue Jan 31, 2012 1:39 pm
by Little John
luis wrote:Nice trick :)
That's exactly what I wanted to say. :-)
Thanks, skywalk!

Regards, LJ