Difference between revisions of "$LET"

From QB64 Wiki
Jump to navigation Jump to search
imported>SMcNeill
(Created page with ' '''$LET''' is precompiler command, which is now usable by modern day cavemen to help include and exclude which sections of code compiles in their program based on OS/bit-siz…')
 
 
(7 intermediate revisions by 3 users not shown)
Line 1: Line 1:
'''$LET''' is precompiler command, which is now usable by modern day [[cavemen]] to help include and exclude which sections of code compiles in their program based on OS/bit-size or other predefined conditions.
[[$LET]] is a precompiler command, which is now usable by modern day [[cavemen]] to help include and exclude which sections of code compiles in their program based on OS/bit-size or other predefined conditions.




{{PageSyntax}}
{{PageSyntax}}
:: $LET variable = expression
: [[$LET]] variable = expression




* $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.
{{PageDescription}}
* Variable names can contain numbers, letters, and periods -- in any order!  $LET 3.2 = TRUE is a perfectly valid variable and expression.
* Unlike [[LET]], [[$LET]] is not optional.
* Expressions can contain one set of leading and/or trailing quotes; and any number of numbers, letters, and periods, in any order.   $LET 3.2 = "TRUE" is also perfectly, but $LET 3.2 = ""TRUE"" will error. (See the double quotes?)
* $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.
* 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/excludeThese are:
** '''WIN''' or '''WINDOWS''' if the user is running QB64 in a Windows environment.
** '''LINUX''' if the user is running QB64 in a Linux environment.
** '''MAC''' or '''MACOSX''' if the user is running QB64 in a macOS environment.
** '''32BIT''' if the user is running a 32-bit version of QB64.
** '''64BIT''' if the user is running a 64-bit version of QB64.
** '''VERSION''', which is set to the version of the QB64 compiler.


''Example 1:''
{{CodeStart}} '' ''
{{Cl|$LET}} ScreenMode = 32
{{Cl|$IF}} ScreenMode = 0 THEN
    {{Cl|CONST}} Red = 4
{{Cl|$ELSEIF}} ScreenMode = 32 THEN
    {{Cl|CONST}} Red = _RGB32(255,0,0)
{{Cl|$END IF}}


{{Cl|COLOR}} Red
{{PageExamples}}
{{Cl|PRINT}} "Hello World"
* See example 1 in [[$IF]].
{{CodeEnd}}


Explaination:
If you look at the code above, you'll see that we have the same CONST defined inside the program.  Normally, we get an error if we try to define a CONST more than once, but the $IF condition here is CHOOSING which CONST we want inside our program.


AS long as Screenmode is 0, the program will exclude the code where CONST Red is defined as color 4.  If Screenmode is 32, CONST Red will be defined as _RGB32(255, 0, 0).
{{PageSeeAlso}}
 
The $LET and $IF statements let us control the code that actually gets compiled, while excluding the other blocks completely.
 
 
''See also:''
* [[Cavemen]]
* [[$IF]]
* [[$IF]]
* [[$ELSE]]
* [[$ELSE]]
* [[$ELSEIF]]
* [[$ELSEIF]]
* [[$END IF]]
* [[$END IF]]
* [[Cavemen]]


{{PageNavigation}}
{{PageNavigation}}

Latest revision as of 16:29, 9 October 2021

$LET is a precompiler command, which is now usable by modern day cavemen to help include and exclude which sections of code compiles in their program based on OS/bit-size or other predefined conditions.


Syntax

$LET variable = expression


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.
  • 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 if the user is running QB64 in a Windows environment.
    • LINUX if the user is running QB64 in a Linux environment.
    • MAC or MACOSX if the user is running QB64 in a macOS environment.
    • 32BIT if the user is running a 32-bit version of QB64.
    • 64BIT if the user is running a 64-bit version of QB64.
    • VERSION, which is set to the version of the QB64 compiler.


Examples

  • See example 1 in $IF.


See also



Navigation:
Keyword Reference - Alphabetical
Keyword Reference - By Usage
Main Wiki Page