Str$()

Syntax

Str$(n)

Remarks

Returns the string representation of the value n. If n is a positive number, Str$() returns a string with a leading space. To remove the leading space, use LTrim$().

Examples

This example uses Str$() to make a numeric variable acceptable as part of a string in a message box. Note that no space is needed after "were" because Str$() has included a space at the beginning of a$.


sales = 2400
a$ = Str$(sales)
MsgBox "Sales this week were" + a$ + " dollars."

You can use the following function to return string representations of numeric variables without the leading space:


Function MyString$(Num)
    If Num >= 0 Then
        MyString$ = LTrim$(Str$(Num))
    Else
        MyString$ = Str$(Num)
    End If
End Function

In another subroutine, String1$ = MyString$(25) is an example of an instruction that calls the preceding function.

See Also

Chr$(), InStr(), Left$(), LTrim$(), Mid$(), Right$(), RTrim$(), String$(), Val()