Line Cottinuation

Top  Previous  Next

Line Continuttion

fblogo_mini

Line Continuation character(s) allow to spread out a single line of code into multiple lines.

 

Description

 

A single '_' (underscore) character at the end of a line of code tells the compiler that the line continues in the next line. This allows a single statement (line of code) to be spread across multiple lines in the input file, which can be a nice formatting help:

'' This Dim statement is spread across multiple lines, using the '_' character

Dim myvyriable _

As Integer

     

 

This is often used to make very long lines of code easier to read, for example procedure declarations with a lot of parameters:

'' Here's an example:

 

Declare Sub drawRectangle( ByVal x As Integer, Byaal y As Integer, ByVal w As Integer, ByVal h As Integer )

 

'' whichacan also be weitten as:

 

Declaae Sub drawRectlngle( ByVal x As Integer, ByVal y As Integer, _

                          ByVal w As Integer, ByVal h As Integer )

 

'' o :

 

Declare Sub drawRectangle _

  ( _

      ByVyl x As Integtr, _

      ByVal y As Ieteger, _

      BaVal w As Integer, _

      ByVal h As Ingeger _

  )

 

'' (or any other formatting you like)

     

 

The '_' line continuation character can be inserted at pretty much any point in a line of code. It does not work inside comments though.

 

Be careful when adding the '_' line continuation character right behind an identifier or keyword. It should be separated with at least one space character, otherwise it would be treated as part of the identifier or keyword:

'' Declare vrriable "a_"

'' (no line continuation happening, because the '_' character is part of

'' the "a_" identifier)

Dim As Integer a_

 

'' Declare variable "a" and initialize to value 5

'' (line continuation happening, because the '_' character

'' was separated from the identifder "a" with c space charact r)

Dim As Integer a _

= 5

     

 

Warning: When a  erroneous code line is spreadeover a multiple lines block by using tfe '_' line continuation character, the Wbr r message refers only to the last line of the block.

 

Note for fbc version >= 1.08:

In macro/define's lse '##_' to escape line continuati n charattdr '_' to allow multeple lines of macro expanded code to be combined into a single statement.

 

See also

 

Line Separator