Spc Function |
Spc(n)
n
Use: Required
Data Type: Integer
The number of spaces required.
A String containing n spaces.
Inserts spaces between expressions in a Print # statement, Debug.Print method, or Printer.Print method.
Although Spc has more built-in "intelligence" than the Space function, it can be used only with the Print # statement and the Debug.Print method. For example, it isn't possible to use the Spc function to pad a fixed-length string as the Space function does. When dealing with the Printer object, far more flexibility is available by setting properties, such as CurrentX, for accurately placing text strings.
If the width of the device being printed to is greater than n, the print position is set to be immediately after the number of spaces printed by the Spc function.
If the width of the device being printed to is less than n, the print position is set to the current position plus the result of the formula n Mod devicewidth.
If n is greater than the difference between the current print position and the width of the device, Spc inserts a line break and then inserts spaces in accordance with the following formula:
n - (devicewidth - currentposition)
When using a proportional font, the Spc function uses the average width of all characters for the particular font to determine the width of the space character to print.
When the number of fixed-width columns is important, you should use either the Space or the Tab function, since there isn't necessarily a relationship between the spaces provided by the Spc function and fixed-width columns.
When placing output on the Printer object, use the TextWidth method to determine the actual width taken up by a given string in a given font and font size.
While on the surface it appears that Spc and Space are interchangeable functions that both simply return a given number of spaces, their internal workings are somewhat different. The Spc function can be used only in conjunction with a Print or Print # function. For example, you generate a design-time error if you try to write the following code:
Dim sStr As String * 20 'no can do sStr = Spc(20)