beautypg.com

Basic programming guide – Remote Processing BASIC for the CX-10 Modbus User Manual

Page 73

background image

BASIC PROGRAMMING GUIDE

2-64

Syntax:

A = STR(10,$(n),format,variable)

Description:

Converts and formats variable into a string and puts it into $(n). Variable A returns irrelevant data.
Formatting is controlled by the format variable. Strings are formatted into one of 3 basic patterns, described
below.

format = 0. Default free format. When number is between ±99999999 and ±0.1, RPBASIC will save integers
and fractions. When numbers are outside this range, the F0 format, described next, is used.

format = Fx. Floating point format. 'x' determines how many digits after the decimal point are saved. When
x = 0, the number of trailing digits will vary and trailing 0's are not saved. 'x' is represented as a hex number.
When format = 0F3H, 3 decimal numbers are printed. An alternate way of setting floating point output is to
make format= the number of decimal numbers plus 240.

format = xyH. Force integer and/or fraction output. Command is same as USING(##.##), where 'x' is the
number digits left of the decimal point and y is to the right. Maximum value for x and y is 7. Use the hex
format to set the number.

Example:

10

String 200,20

20

C = 23.45

30

F = 0

40

A = STR(10,$(0),F,C)

50

PRINT "Variable value, before formatting:",C

60

PRINT "String in free format:",$(0)

70

F = 0F2H

80

A = STR(10,$(0),F,C)

90

PRINT "Using floating point format:",$(0)

100 F=52H
110 A=STR(10,$(0),F,C)
120 PRINT "Using #####.## format:",$(0)
run
Variable value, before formatting: 23.45
String in free format: 23.45
Using floating point format: 2.34 E+1
Using #####.## format:

23.45

ERROR

BAD ARGUMENT When function is out of range or string data is incorrect.