Hardware manual
Basic Program Examples Impact Reference Guide
Datalogic Automation Inc. 5-30
thisyearday = YEARDAY yields thisyearday = 57
Basic Program Examples
The following examples of Basic tool code illustrate some simple function calls and shows how to construct
Basic statements. Each example is preceded by explanatory text which will help explain its purpose.
This example uses the CHR function to create a string (ab_) with the last character incrementing from ‘a’ to
‘z’ each time the code is run.
’ First, initialize the ascii value (the character’s ascii code) for
’ the last character in the string. If it is zero or greater than 121
’ (the value for z), then set it to 96 (the value of a).
IF ascii_counter = 0 OR ascii_counter > 121 THEN
ascii_counter = 96
END IF
’ Now, increment the counter
ascii_counter = ascii_counter + 1
’ This line converts the ascii value to a string value
char_string = chr(ascii_counter)
’ Finally, this line appends the incremented character to the
’ fixed string
name_string = "ab" & char_string
This example shows the use of parentheses in calculations which find the intersection point of two line seg-
ments. The segments are defined by four points.
The first line segment is defined by points X1,Y1 to X2,Y2
The second line segment is defined by point X3, Y3 to X4, Y4
’ First, find the slope of the first line segment
m1 = (y2 - y1) / (x2 - x1)
’ Now find its intercept
b1 = y1 - (m1 * x1)
’ This code finds the slope of the second line segment
m = (y4 - y3) / (x4 - x3)
’ Now find its intercept
b2 = y3 - (m2 * x3)
’ Now calculate the x and y coordinates of the intersection of
’ the two line segments
x = (b2 - b1) / (m1 - m2)
y = (m1 * x) + b1
Here are several examples of various functions and assignments.
Example 1
’ This example assigns an integer value of -35 to the variable
’ "cost," then assigns its absolute value to the real variable
’ abs_value using the ABS function.
cost = -35
abs_value = abs(cost)
Example 2
’ This example uses the ASC function to find the ascii code
’ value of the letter "A." It assigns the integer value 65 to the
’ variable asc_value.
asc_value = asc("A")
Example 3
’ This example uses the CHR function to return the letter that
’ corresponds to the ascii code assigned in the previous