Line numbers and Labels

Line numbers are Integers in the range 1 to 65535, which serve to identify program lines. PowerBASIC takes a relaxed stance toward line numbers. They can be freely interspersed with labels, and used in some parts of a program and not others. In fact, they do not even need to follow in numeric sequence. No two lines can have the same number, and no line can have both a label and a number. Line numbers are essentially labels.

While line numbers and labels serve the same purpose, their usage is slightly different. Line numbers are just a concession to compatibility with Interpretive BASIC. Line numbering can lead to bad programming style. Since the numbers themselves can be in any order, they give a false sense of structure to a program. We recommend that you avoid line numbers, and use labels instead.

Using labels instead of numbers allows you to make the flow of your program much more readable. For example:

GOSUB BuildQuarks

tells you much more than

GOSUB 1723

Each label must appear on a line by itself (though a comment may follow) and it serves to identify the statement immediately following it. Labels must begin with a letter and contain any number of letters, digits, and an underscore. Case is insignificant - THISLABEL, thislabel, and ThisLabel are all the same. A colon must follow a label, however, and statements that refer to the label must not include the colon.

MSGBOX "Now Sorting Invoices"

GOSUB SortInvoices

MSGBOX "All Done!"

EXIT FUNCTION

 

SortInvoices: ' This is a legal label

{sorting code goes here}

RETURN

The following is illegal, however:

ExitPoint: a = a + 1 ' a label must be on a line by itself

Finally, it should be noted that symbol names must be unique: a label may not share the name of any other symbol (Sub name, Function name, user-defined type or union definition, variable name, etc), and they are local to the Sub or Function in which they appear.

 

See Also

Long lines

Statement separation

Structured Programming

Variables