Spc Function

See Also3TBGGDE              ExampleGUA87M>Low

Skips a specified number of spaces in a Print # statement or Print method.

Syntax

Spc(number)

Remarks

This function can be used only with the Print # statement or the Print method.

The argument number is an integer between 0 and 32,767, inclusive, that determines the number of blank characters to print.

Note that the Spc function does more than move to a new print position.  The number argument specifies how many blank or space characters are printed starting at the current print position.  When you use Spc on a line with other arguments to either the Print # statement or the Print method and you place no separator (a semicolon or comma) after it, a semicolon (;) is assumed except when Spc appears at the end of a line. For example, Print #1, Spc(10) FixLen1$ and Print#1, Spc(10); FixLen1$ are equivalent.

When used with files, Spc behaves in the following way:

         If number is less than the output line width, the next print position immediately follows the number of spaces printed.

         If number is greater than the output-line width, Spc calculates printposition =  number Mod width and generates the number of spaces indicated by that calculation, starting at the current print position.

         If the difference between the current print position and the output-line width is less than number (or number Mod width), the Spc function skips to the beginning of the next line and generates a number of spaces equal to number - (width - currentprintposition).

 

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 size95MO9S3 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.  Make sure your tabular columns are wide enough to accommodate wider letters.


See Also

Print Method9V51E5

Print # Statement12JHDL9

Space, Space$ Function3TBE7D

Tab FunctionLANTAB

Width # StatementQ6GH4W


Spc Function Example

The example uses the Spc function to embed 10 spaces in an output file.  To try this example, paste the code into the Declarations section of a form.  Then press F5 and click the form.

 

Sub Form_Click ()

   Dim Msg                               ' Declare variable.

   Open "TESTFILE" For Output As #1      ' Create sample data file.

   Print #1, "This is a test of the "; Spc(10); "Spc function."

   Close #1                              ' Close file.

   Open "TESTFILE" For Input As #1       ' Reopen the file for input.

   Input #1, Msg                         ' Read the data.

   Close #1                              ' Close file.

   MsgBox Msg                            ' Display file contents.

   Kill "TESTFILE"                       ' Remove file from disk.

End Sub