PDA

View Full Version : Splitting code on multiple lines



TBUser54
09-02-2012, 06:42
Just wondering is it possible to split a long line of code in a line of two, if so what character should I use, as to not confuse the compiler?

From Richard West

Charles Pegge
09-02-2012, 07:32
Hi Richard,

Use a space and an underscore character, then you can split the line after the underscore.

You can also add comments after the underscore.

Most Basics will support this.

Charles

Petr Schreiber
09-02-2012, 10:23
Hi,

since version 1.8.6.0, ThinBASIC supports "implicit line continuation". That means, you can do this:


Long MyNumbers(10)

' -- Fill from element 1 on, no need for continuation character as long as line ends with comma
MyNumbers(1) = 1, 2, 3, 4, 5,
6, 7, 8, 9, 10

' -- Parameters spread on multiple lines for better clarity
MyFunction(
"Petr",
"Schreiber",
128
)

Function MyFunction(sName As String, sSurName As String, nAge As Long)
MsgBox 0, sName + $CRLF + sSurName + $CRLF + nAge
End Function


To cite Eros from the announcement:


The general rule is:


if statement (line) ends with a delimiter (a comma, a math operator, ...) parser will ignore end of line and will continue parsing next line.
In the above cases underscore sign (used to indicate line continuation) is not necessary.




Petr