$LET

From QB64 Phoenix Edition Wiki
Revision as of 22:06, 17 November 2024 by RhoSigma (talk | contribs)
Jump to navigation Jump to search

$LET is a precompiler metacommand. It is used to define or redefine precompiler variables for use in the $IF...$ELSE...$END IF block statements.


Syntax

$LET variable = value


Description

  • Unlike LET, $LET is not optional.
  • $LET a = 12 sets a precompiler variable "a" to the value of 12. This variable is only valid for the precompiler itself and does nothing to affect the values of any variable/constant which might also be called "a" in the program.
  • Variable names must follow QB64's variable naming conventions. They will be capitalized automatically.
  • Values may contain any number of periods to separate numbers or words in a string, e.g. in version numbers such as 3.14.1 or strings like MARY.HAD.A.LITTLE.LAMB etc..
    • Note that strings may not contain spaces and therefore may be given without leading/trailing quotes.
  • You can check a precompiler variable against special values DEFINED and UNDEFINED, in order to assess whether the variable has already been assigned a value. Useful for code in libraries which may be repeated.
  • The precompiler comes with some preset values which can be used to help determine which code blocks to include/exclude. These are:
    • WIN or WINDOWS is -1 (true) if the user is running QB64 in a Windows environment, it is 0 (false) otherwise.
    • LINUX is -1 (true) if the user is running QB64 in a Linux environment, it is 0 (false) otherwise.
    • MAC or MACOSX is -1 (true) if the user is running QB64 in a macOS environment, it is 0 (false) otherwise.
    • 32BIT is -1 (true) if the user is running a 32-bit version of QB64., it is 0 (false) otherwise.
    • 64BIT is -1 (true) if the user is running a 64-bit version of QB64., it is 0 (false) otherwise.
    • VERSION, which is set to the version of the QB64 compiler.
  • Some new presets have been introduced with QB64-PE v4.0.0, these are:
    • _QB64PE_ is always -1 (true), it indicates the use of the QB64 Phoenix Edition compiler at least v.4.0.0
    • _ASSERTS_ is 1 (one) if $ASSERTS or $ASSERTS:CONSOLE is used, it is 0 (zero) otherwise.
    • _CONSOLE_ is 1 (one) if a console is active either by using $CONSOLE directly or implied by $ASSERTS:CONSOLE, it is 2 (two) if $CONSOLE:ONLY is set, it is 0 (zero) if no console is available (both console variants may appear multiple times in a program, the last found one determines the final state).
    • _DEBUG_ is 1 (one) if $DEBUG is used, it is 0 (zero) otherwise.
    • _EXPLICIT_ is 1 (one) if the program uses OPTION _EXPLICIT, it is 0 (zero) otherwise (note OE also implies OPTION _EXPLICITARRAY).
    • _EXPLICITARRAY_ is 1 (one) if the program uses OPTION _EXPLICITARRAY or OPTION _EXPLICIT, it is 0 (zero) otherwise.
Important notes regarding the preset values
  • Although there's for simplicity no internal protection against it, don't overwrite the presets using $LET, always consider the presets as read-only.
  • The presets shall mainly serve the ability, for library makers, to check what features are active in a program, don't misuse it to enforce certain features, e.g.
  • don't check for _CONSOLE_ and force to open one, if none is there already
  • don't check for _EXPLICIT_ and force it, if it's not in effect already
  • Think of it like checking for WINDOWS and if it's not forcing the user to buy a Windows system or checking for 32BIT and if it's not forcing the user to downgrade his 64-bit system. You wouldn't do that, right? And by that you should not enforce things, which the user did not use in his program already.


Availability

  • In QB64-PE v4.0.0 several new presets got added into the precompiler (see above).


Examples

  • See example 1 in $IF.


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link