CStr (function)

Syntax

CStr(expression)

Description

Converts expression to a String.

Comments

Unlike Str$ or Str, the string returned by CStr will not contain a leading space if the expression is positive. Further, the CStr function correctly recognizes thousands and decimal separators for your locale.

Different data types are converted to String in accordance with the following rules:

 

Data Type

CStr Returns

 

Any numeric type

A string containing the number without the leading space for positive values.

 

Date

A string converted to a date using the short date format.

 

Boolean

A string containing either TRUE or FALSE.

 

Null variant

A runtime error.

 

Empty variant

A zero-length string.

Example

This example displays the value of a Double converted to a String.

Sub Main()

  s# = 123.456
  MsgBox "The string value is: " & CStr(s#)
End Sub

See Also

CCur (function); CBool (function); CDate, CVDate (functions); CDbl (function); CInt (function); CLng (function); CSng (function); CVar (function); CVErr (function); String (data type); Str, Str$ (functions).

More information

C