Skip to Content
VB & VBA in a Nutshell: The Language
book

VB & VBA in a Nutshell: The Language

by Paul Lomax
October 1998
Intermediate to advanced
656 pages
16h 10m
English
O'Reilly Media, Inc.
Content preview from VB & VBA in a Nutshell: The Language
Spc Function

Syntax

Spc(n)

n

Use: Required

Data Type: Integer

The number of spaces required.

Return Value

A String containing n spaces.

Description

Inserts spaces between expressions in a Print # statement, Debug.Print method, or Printer.Print method.

Rules at a Glance

  • 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, ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Absolute Beginner's Guide to VBA

Absolute Beginner's Guide to VBA

Paul McFedries
Visual Basic 2015 Unleashed

Visual Basic 2015 Unleashed

Alessandro Del Sole

Publisher Resources

ISBN: 1565923588Catalog PageErrata