STR

Top  Previous  Next

Action

Returns a string representation of a number.

 

 

Syntax

var = STR( x)

 

 

Remarks

var

A string variable.

X

A numeric variable.

 

The string must be big enough to store the result.

You do not need to convert a variable into a string before you print it.

When you use PRINT var, then you will get the same result as when you convert the numeric variable into a string, and print that string.

The PRINT routine will convert the numeric variable into a string before it gets printed to the serial port.

 

As the integer conversion routines can convert byte, integer, word and longs into a string it also means some code overhead when you do not use longs. You can include the alternative library named mcsbyte.lbx then. This library can only print bytes. There is also a library for printing integers and words only. This library is named mcsbyteint.

When you use these libs to print a long you will get an error message.

 

 

See also

VAL , HEX , HEXVAL , MCSBYTE , BIN

 

 

Difference with VB

In VB STR() returns a string with a leading space. BASCOM does not return a leading space.

 

 

 

Example

Dim A As Byte , S As String * 10

A = 123

S = Str(a)

Print S                                                     ' 123

'when you use print a, you will get the same result.

'but a string can also be manipulated with the string routines.

End