ZB2B7‖

R4trJ‖Str Function

Z8JfH‖The Str function converts the contents of variables into a string. It handles numeric values, dates, strings and currency values.

Zxy4r‖Positive numbers are preceded by a blank space. Negative numbers are preceded by a minus sign.

note

A5Fyi‖For numeric values the string returned by the Str function is locale-independent. Hence the dot is used as the decimal separator when needed.


HjAty‖If a string is passed as argument, it is returned without any changes.

nfPG2‖Dates are converted into locale-dependent strings.

FVEx2‖Syntax:


    NEAum‖Str (Value As Variant)
  

GePPP‖Return value:

String

WADQ4‖Parameters:

sw7rF‖ Value: Any value to be converted into a string.

SEjHR‖Error codes:

5 Invalid procedure call

EFSA4‖Example:

hHwSa‖Below are some numeric examples using the Str function.


    Sub ExampleStr_1
    74DXW‖    ' Note the blank space at the beginning of the returned strings
        MsgBox Str(10) ' " 10"
        MsgBox Str(10.5) ' " 10.5"
        MsgBox Str(-12345 + 1.3) ' " -12346.3"
        MsgBox Str(10000 / 3) '  " 3333.33333333333"
    pogg9‖    ' Strings passed as arguments are left unchanged
        MsgBox Str("A123") ' "A123"
    End Sub
  

kjJa8‖Use the LTrim function to remove the blank space at the beginning of the returned string.


    Sub ExampleStr_2
        MsgBox Str(10.5) ' " 10.5"
        MsgBox LTrim(Str(10.5)) ' "10.5"
    End Sub
  

FDMfX‖The Str function can also handle Date variables.


    Sub ExampleStr_3
        Dim aDate as Date, aTime as Date
        aDate = DateSerial(2021, 12, 20)
        aTime = TimeSerial(10, 20, 45)
        Print Str(aDate) ' "12/20/2021"
        Print Str(aTime) ' "10:20:45"
    End sub