How Do They Help When Writing Programs Comments
The text in a program that follows the ‘ symbol up to the end of the line is ignored by the compiler and represents a comment.
Comments allow you to add descriptions and explanations for those programmers who will later need to understand your program. By commenting the entire program, you save time. In addition, comments make the program easier to understand both for the author and for those to whom, if necessary, you will explain the program code.
Comments are also useful when debugging programs. They allow you to temporarily disable lines of program code.
Below are possible ways to use comments in program code:
Dim a As Integer ' ************************** ' * a — integer variable * ' ************************** Dim b As String ' b — string variable ' b = sin(2) — this operator is disabled
Line Continuation
Placing a space character and an underscore (_) at the end of a line makes it possible to split a single statement into several lines, while the compiler will treat them as a single statement. It should be remembered that:
- string constants cannot be split by line continuation;
- no more than seven continuations of the same line are allowed;
- a line itself cannot exceed 1024 characters.
In the following example, the first construction is a line-broken version of the second:
ActiveCell.Offset(rowoffset:=0, _ columnoffset:=1).Value = Sum
and
ActiveCell.Offset(rowoffset:=0, columnoffset:=1).Value = Sum
To split a string constant across lines, it must be represented as the result of concatenating several string constants, and the line break must occur at the concatenation operation (&).
Here is an example of correct and incorrect line breaks for the string « Visual Basic for Applications »:
Incorrect break:
s = "Visual Basic for _ Applications"
Correct break:
s = "Visual Basic " _ & "for Applications"
Placing Several Statements on One Line
Using the colon sign (:) allows you to place several statements on one line. Thus, the following two constructions are equivalent:
x = 1 ' variable x contains 1 x = x + 2 ' variable x contains 3
and
x = 1 : x = x + 2