$FORMAT

From QB64 Phoenix Edition Wiki
Revision as of 00:21, 22 February 2025 by RhoSigma (talk | contribs)
Jump to navigation Jump to search

The $FORMAT metacommand will control the code formatting behavior of the IDE and the -y command line switch (formatting mode).


Syntax

{REM | ' } $FORMAT:{ON|OFF}


Description

Note
This metacommand does not affect the compiled program in any way. It's just a simple tool to control the code formatting behavior of the IDE and the command line formatting mode. That's why we decided to implement it as a commented legacy style metacommand behind a REM or ' to avoid compiler errors.
  • $FORMAT:OFF will temporarily suppress all line indention and auto single-spacing of code elements, so that you may space and align stuff to your free desire (e.g. numbers in DATA lines).
  • $FORMAT:ON is used to restore the regular formatting as set in the Options > Code Layout dialog or the format settings given on the command line when using the -y formatting mode.
    • The ON and OFF variants of this metacommand do not nest, hence there must not be a matching count of ON and OFF commands and you also must not necessarily switch it back ON at the end of your program.
    • QB64pe always makes sure that formatting is ON at the very first line of your program.
    • The commands can also be used in $INCLUDEd files and no matter what state is finally active in the included file, it won't affect the main code which will always keep its current state as last set before the $INCLUDE.


Availability


Examples

Example
Showcasing the use of $FORMAT:OFF and $FORMAT:ON.
'the layout starts with default settings as given
'in the Options > Code Layout dialog, for this
'example we used the following settings:
'   Auto Indent = ON, Indent Spacing = 4,
'   Auto single-spacing code elemets = ON
TYPE Test
    one AS INTEGER
    two AS _BYTE
    three AS STRING * 3
    four AS _FLOAT
END TYPE

DATA 123,45,67,890
DATA 2,456,5,43
DATA 45,9,765,6

'$FORMAT:OFF
'will suppress indention and single-spacing until we
'switch it back again, now we can space and align our
'code elements freely and it will not be reformatted,
'note that keywords will still be changed according
'to the chosen case, only indention and spacing is off
TYPE   Test2
 one   AS  INTEGER
 two   AS _BYTE
 three AS  STRING*3
 four  AS _FLOAT
END TYPE   

DATA 123,  45,  67, 890
DATA   2, 456,   5,  43
DATA  45,   9, 765,   6

'$FORMAT:ON
'this restores back to defaults, hence
'indention and single-spacing is done again
TYPE Test3
    one AS INTEGER
    two AS _BYTE
    three AS STRING * 3
    four AS _FLOAT
END TYPE

DATA 123,45,67,890
DATA 2,456,5,43
DATA 45,9,765,6


See also



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