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

Just starting out? Need help? Post your questions and find answers here.
SniffTheGlove
Enthusiast
Enthusiast
Posts: 122
Joined: Sat Nov 19, 2011 6:51 pm

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

Post 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
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

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

Post 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.
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
SniffTheGlove
Enthusiast
Enthusiast
Posts: 122
Joined: Sat Nov 19, 2011 6:51 pm

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

Post 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.
User avatar
skywalk
Addict
Addict
Posts: 4210
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

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

Post 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
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

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

Post by luis »

@skywalk

Nice trick :)
"Have you tried turning it off and on again ?"
A little PureBasic review
Little John
Addict
Addict
Posts: 4773
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

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

Post by Little John »

luis wrote:Nice trick :)
That's exactly what I wanted to say. :-)
Thanks, skywalk!

Regards, LJ
Post Reply