Hardware manual
Basic Program Examples Impact Reference Guide
Datalogic Automation Inc. 5-32
’ variable reverse_string.
reverse_string = strreverse(resulting_string)
This example shows how to format a real value to a specified number of digits.
’This is the real value to format
real_value = 123.1234567890
’Set the number of digits of precision desired
precision_int = 1
’The Basic function "instr" finds the location of the decimal point in the real
value (4). The function "mid" returns the numbers in the real value beginning at
1 and ending at the location of the decimal point plus the number of digits of
precision (4+1=5). This creates the string formatted_string with a value of
"123.4".
formatted_string = mid(real_value,1,instr(real_value,".") + precision_int)
’This code creates the same value as the previous line of code, except the string
is automatically converted to a real value of 123.4 (formatted_value).
formatted_value = mid(real_value,1,instr(real_value,".") + precision_int)
This example shows how to change directories, open a file, write values into it, then read those values.
NOTE: This example works in the CPM Basic control only. It will not work in the VPM Basic tool.
’first open the file for write and assign the file number 1, then generate a ran-
dom number to write to the file
open "myfile.txt" for output as 1
x = ROUND(rnd)
’now, write the result to the file
print #1, "This is a first result. x = " & x & "\n"
’repeat for two more records
x = ROUND(rnd)
print #1, "This is a second result. x = " & x & "\n"
x = ROUND(rnd)
print #1, "This is a third result. x = " & x & "\n"
’close the file
close 1
’now open the file for reading, read the first record, assign the input string to
the variable thestring, then close the file
open "myfile.txt" for input as 1
LINE INPUT #1, thestring
close 1
’This section of the example, changes the directory to the temp directory,
assigns the directory name to the variable new_dir, opens a file for reading,
reads the first record, then closes the file
chdir curdir & "/temp"
new_dir = curdir
open "myfile2.txt" for input as 2
LINE INPUT #2, thestring2
close 2