Space Function (Visual Basic)

Returns a string consisting of the specified number of spaces.

Public Shared Function Space(ByVal Number As Integer) As String

Parameters

  • Number
    Required. Integer expression. The number of spaces you want in the string.

Exceptions

Exception type

Error number

Condition

ArgumentException

5

Number < 0.

See the "Error number" column if you are upgrading Visual Basic 6.0 applications that use unstructured error handling. (You can compare the error number against the Number Property (Err Object).) However, when possible, you should consider replacing such error control with Structured Exception Handling Overview for Visual Basic.

Remarks

The Space function is useful for formatting output and clearing data in fixed-length strings.

Example

This example uses the Space function to return a string consisting of a specified number of spaces.

Dim TestString As String 
' Returns a string with 10 spaces.
TestString = Space(10)
' Inserts 10 spaces between two strings.
TestString = "Hello" & Space(10) & "World"

Requirements

Namespace:Microsoft.VisualBasic

**Module:**Strings

Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)

See Also

Reference

String Manipulation Summary

SPC Function

ArgumentException