Spc Function

Description

Used with the Print # statement or the Print method to position output.

Syntax

Spc(n)

The n argument is the number of spaces to insert before displaying or printing the next expression in a list.

Remarks

If n is less than the output-line width, the next print position immediately follows the number of spaces printed. If n is greater than the output-line width, Spc calculates the next print position using the formula:

currentprintposition + (n Mod width)

For example, if the current print position is 24, and the output-line width is 80 and you specify Spc(90), the next print will start at position 34 (current print position + the remainder of 90/80). If the difference between the current print position and the output-line width is less than n (or n Mod width), the Spc function skips to the beginning of the next line and generates a number of spaces equal to n - (width - currentprintposition).

Note Make sure your tabular columns are wide enough to accommodate wide letters.

When you use the Print method with a proportionally spaced font, the width of space characters printed using the Spc function is always an average of the width of all characters in the point size for the chosen font. However, there is no correlation between the number of characters printed and the number of fixed-width columns those characters occupy. For example, the uppercase letter W occupies more than one fixed-width column and the lowercase letter I occupies less.

See Also

Mod Operator, Print # Statement, Print Method, Space Function, Tab Function, Width # Statement.

Example

This example uses the Spc function to position output in a file and in the Debug window.


' The Spc function can be used with the Print # statement."TESTFILE" For Output As #1    ' Open file for output.#1, "10 spaces between here"; Spc(10); "and here."#1    ' Close file.

The following statement causes the text to be printed in the Debug window (using the Print method), preceded by 30 spaces.


Debug.Print Spc(30); "Thirty spaces later..."