Page 1 of 1

How to use Compiler Custom Constants

Posted: Fri May 25, 2012 5:19 pm
by TeraByte
I am trying to use the Compiler > Compiler Options > Constants > Custom Constants.

Here's what I tried:
1. Create a custom constant called #DebugLog and click "Add".
2. Now #DebugLog appears in the Custom Constants list.

In my code, I have

Code: Select all

CompilerIf #DebugLog
  CompilerError "Debug log is on"
CompilerElse
  CompilerError "Debug log is off"
CompilerEndIf
Compiler reports "Constant not found:#DebugLog."

So next I tried this:

Code: Select all

#DebugLog = 0

CompilerIf #DebugLog
  CompilerError "Debug log is on"
CompilerElse
  CompilerError "Debug log is off"
CompilerEndIf
This works fine. However, it apparently has nothing to do with my Custom Constant because I can delete it from the Compiler options and it still works.

So my question is how am I supposed to properly use the Compiler Custom Constant ? I was hoping to define it as a Compiler Custom Constant and then enable/disable it from the compiler options.

Thank you.

Re: How to use Compiler Custom Constants

Posted: Fri May 25, 2012 5:22 pm
by STARGĂ…TE

Code: Select all

;#DebugLog = 1

CompilerIf Defined(DebugLog, #PB_Constant)
  CompilerError "Debug log is on"
CompilerElse
  #DebugLog = 0
  CompilerError "Debug log is off"
CompilerEndIf 


Re: How to use Compiler Custom Constants

Posted: Fri May 25, 2012 7:03 pm
by Little John
TeraByte wrote:I am trying to use the Compiler > Compiler Options > Constants > Custom Constants.

Here's what I tried:
1. Create a custom constant called #DebugLog and click "Add".
Assign a value of your choice to the constant in the IDE before clicking "Add":
#DebugLog = 1

Re: How to use Compiler Custom Constants

Posted: Fri Feb 07, 2020 9:17 am
by andreasahlen
Set your contant in Constants => Custom Constants in Compiler Options
#DEBUGMODE = 1
Eval constant value using:

Code: Select all

; Main
CompilerIf Defined(DEBUGMODE, #PB_Constant)
  Debug "DEBUG mode"
CompilerEndIf

Re: How to use Compiler Custom Constants

Posted: Fri Feb 07, 2020 2:46 pm
by kenmo
You can use either method.

1. You might be used to languages like C, where you can just #define DEBUGLOG and check if it's defined or not.
In PureBasic you can't just define a constant name, it must have a value (maybe the compiler should warn you!).
So use #DebugLog=1 or #DebugLog=0 then check:

Code: Select all

CompilerIf #DebugLog
OR 2. Define the constant #DebugLog=AnyValue and use the checkbox to enable or disable it, then check:

Code: Select all

CompilerIf Defined(DebugLog, #PB_Constant)

Re: How to use Compiler Custom Constants

Posted: Sat Feb 08, 2020 1:25 am
by BarryG
TeraByte wrote:Here's what I tried:
1. Create a custom constant called #DebugLog and click "Add".
Sounds like you didn't add a value to the constant -> https://i.imgur.com/vo4exWu.png

Re: How to use Compiler Custom Constants

Posted: Sat Feb 08, 2020 3:21 am
by Josh
... 8 years later :mrgreen:

Re: How to use Compiler Custom Constants

Posted: Sat Feb 08, 2020 4:15 am
by BarryG
I've bookmarked this forum with "View new posts", and this thread showed up. I don't look at the dates. andreasahlen was the one who revived it.

Re: How to use Compiler Custom Constants

Posted: Sat Feb 08, 2020 4:32 am
by kenmo
:lol: I did not notice the age either, I just read "View active topics"

Re: How to use Compiler Custom Constants

Posted: Sat Feb 08, 2020 4:38 am
by BarryG
A lot of the time, someone will post a link to an older post too, and then someone will go there and read that, not realising it's 10+ years old. They might then reply to it, thus reviving it. No big deal, IMO. It adds value to old posts to keep them updated with relevant new info.