Str, Str$ Functions

See AlsoCCEIPK              Example3XXR00G>Low

Return a string representation of the value of a numeric expression71RISN.

Syntax

Str[$](number)

Remarks

Str returns a Variant8PHEAW3; Str$ returns a String.

Use Str[$] to convert simple numeric values to strings.  Use the Format[$] function to convert numeric values you want formatted as dates, times, or currency or in other user-defined formats.

When numbers are converted to text, a leading space is always reserved for the sign of number.  If number is positive, the string returned by Str[$] contains a leading space and the plus sign is implied.  Format[$] doesn't include a leading space.

The Val function complements Str[$] by returning the numeric value of a string.


See Also

Format, Format$ Function1EQ2BPO

Val FunctionLANVAL


Str, Str$ Function Example

The example uses Str to return a string representation of the values contained in two variables.  Note that because the numbers are positive, a space for the implied plus sign precedes the first string character.  To try this example, paste the code into the Declarations section of a form.  Then press F5 and click the form.

 

Sub Form_Click ()

   Dim Dice1, Dice2, Msg                 ' Declare variables.

   Randomize                             ' Seed random number generator.

   Dice1 = Int(6 * Rnd + 1)              ' Generate first die value.

   Dice2 = Int(6 * Rnd + 1)              ' Generate second die value.

   Msg = "You rolled a" & Str(Dice1)

   Msg = Msg & " and a" & Str(Dice2)

   Msg = Msg & " for a total of"

   Msg = Msg & Str(Dice1 + Dice2) & "."

   MsgBox Msg                            ' Display message.

End Sub