Keep all manualsas a product component during the life span ofthe product.
Passallmanuals to future users/owners of the product.
AKD BASIC User Guide |
Record of Document Revisions:
RevisionRemarks
06/2011, Rev ALaunch Version for M_01-06-00-000
Windows is a registered trademark of Microsoft Corporation
AKD is a registered trademark of Kollmorgen Corporation
Current patents:
US Patent 5,646,496 (used in control card R/D and 1 Vp-p feedback interface)
US Patent 5,162,798 (used in control card R/D)
US Patent 6,118,241 (used in control card simple dynamic braking)
Technical changes which improve the performance of the device may be made without prior notice.
Printed in the United States of America
This document is the intellectual property of Kollmorgen™. All rights reserved. No part of this work may
be reproduced in any form (by photocopying, microfilm or any other method) or stored, processed, copied
or distributed by electronic means without the written permission of Kollmorgen™.
Kollmorgen™ | March 30, 20122
This page intentionally left blank.
3Kollmorgen™ | March 30, 2012
AKD BASIC User Guide |
Table of Contents
1 About this User Guide16
2 Program View17
2.1 Toolbar Options17
2.1.1 New ...17
2.1.2 Save / Save As17
2.1.3 Open18
2.1.4 Edit Parameters Section18
2.1.5 Compile / Download / Run18
2.1.6 Continue / Pause / Stop18
2.1.7 Debug18
2.1.8 View19
2.1.9 Format Document19
2.1.10 Insert Code Snippet19
2.1.11 Upload?19
2.1.12 Lock19
3 AKDBASICLanguage20
3.1 AKD BASIC Program Structure20
3.1.1 Local Variables20
3.1.2 Global Variables20
3.2 Program Sections21
3.2.1 Program Template21
3.2.2 Setup Parameter Definitions21
3.2.3 Global Variables, Constants, and Aliases22
3.2.4 Variable Definitions22
3.2.5 Constant Definitions22
3.2.6 Alias Definitions23
3.3 Main Program, Subroutines, Functions & Interrupt Handlers23
3.3.1 Main Definitions23
3.3.2 Subroutine Definition24
3.3.3 Function Definition25
3.3.4 Interrupt Handler Definition25
3.4 Language Definition26
3.4.1 Lexical Conventions26
3.4.2 Identifiers26
3.4.3 Data Types26
3.4.4 Literal Constants27
3.4.5 Decimal Integer Constants27
3.4.6 Hexadecimal Constants27
3.4.7 Floating-Point Constants27
3.5 Statements28
3.5.1 Alias28
3.5.2 Call28
Kollmorgen™ | March 30, 20124
AKD BASIC User Guide |
3.5.3 Cls28
3.5.4 Const28
3.5.5 Dim29
3.5.6 Exit29
3.5.7 For…Next29
3.5.8 Function30
3.5.9 GoTo30
3.5.10 If…Then…Else30
3.5.11 $Include31
3.5.12 Input31
3.5.13 Interrupt … End Interrupt31
3.5.14 MOVE.ABORT31
3.5.15 MOVE.GOABS31
3.5.16 MOVE.GOHOME31
3.5.17 MOVE.GOREL32
3.5.18 MOVE.GOUPDATE32
3.5.19 MOVE.GOVEL32
3.5.20 On Error GoTo32
3.5.21 Pause( )33
3.5.22 Print33
3.5.23 Example33
3.5.24 VM.RESTART33
3.5.25 Select Case33
3.5.26 Static34
3.5.27 Stop34
3.5.28 Sub…End Sub34
3.5.29 Swap35
3.5.30 When35
3.5.31 While…Wend35
3.6 Built-in Functions35
3.6.1 Parameters and Commands36
3.7 Expressions37
3.7.1 Arithmetic Expressions37
3.7.2 Numeric Operators37
3.7.3 Logical Operators37
3.7.4 String Operators38
3.7.5 Example38
3.8 Function Invocation38
3.8.1 $INCLUDE38
3.9 Arrays and Function Parameter Lists39
3.9.1 Optimizations39
3.10 ModBus TCP/IP41
3.10.1 ModBus Parameter Table41
3.10.2 ModBus Register and Data Types41
3.10.3 User Created Variables with Assigned Modbus Address Numbers41
This guide describes the operation and use of the AKD drive. Each section details a specific
topic related to the use of the product in simple terms which will help you get the most from the
product. Each section includes examples to help guide you in setting up and using the various
features available in the drive.
This guide is for users who have installed and tested the drive according to the AKD InstallationManual. The AKD Installation Manual is included on the product CD and contains critical safety
information.
Kollmorgen™ | March 30, 201216
AKD BASIC User Guide | 2 Program View
2Program View
The program view in AKD WorkBench is specific to AKD BASIC drives and can only be accessed using
an AKD BASIC drive type in either online or offline mode. Programs can be compiled in offline mode, but
an AKD BASIC drive must be connected to download and run a program.
2.1 Toolbar Options
The toolbar at the top of the program view contains a number of tools to assist you in programming.
2.1.1 New ...
The Program view loads as an empty window. Create a new program by clicking the new icon in the
upper-left corner and selecting either BASIC or BASICUsing Current Drive Params. The BASIC
selection will load an empty template. The BASICUsing Current Drive Params selection will populate
the template with all current drive values. Then select the location and name of your new project file, and
click save.
This will load the BASICtemplate from which you can begin programming.
2.1.2 Save / Save As
Once you have written your program, save it using the "Save" or "Save As" function on the toolbar
.
17Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 2 Program View
2.1.3 Open
To open a previous project file click the "Open" functionand locate your file in the explorer.
2.1.4 Edit Parameters Section
Clicking on the Edit Params Section toolwill prompt you to populate the Params section of your code
with all the current drive settings. Clicking yes will overwrite all current param defintions with the current
drive values.
2.1.5 Compile / Download / Run
The Compile button will compile your source code to binary so that you may download the program to the
drive.
The Download button will download your compiled code and source code to the drive by default. If you do
not wish to download the source code to the drive, go to the options menu, choose download and deselect download source with binary.
The run button will issue a VM.START to start the BASIC program in the drive. If the active BASIC program in the editor is different than the program in the drive, the run button will compile and download the
program before running.
2.1.6 Continue / Pause / Stop
The Continue, Pause, and Stop optionsallow you to control your program while it is running.
2.1.7 Debug
The Debugger allows you to set break points and step through your program.
Kollmorgen™ | March 30, 201218
AKD BASIC User Guide | 2 Program View
2.1.8 View
Use Find and Replace to find keywords in your program and replace them with a new keyword
Use the Go To Line to go to a specific line of code
Watch will open the expression evaluator tab. The expression evaluator is only valid while using the
debugger. You can evaluate any drive parameter or user defined variable when the program is paused by
the debugger.
Call Stack will open the call stack tab
2.1.9 Format Document
The format document toolimplements correct line indentation across all code.
2.1.10 Insert Code Snippet
The Insert Code Snippet toolpresents a list of existing code snippets, which can be selected and
inserted into the program at the point where the cursor is currently placed.
2.1.11 Upload?
The upload tool uploads the source code from the drive. If the source code has not been downloaded, this
option is not available. The tools menu allows you to select if the source code is to be downloaded with
the binary.
2.1.12 Lock
The lock tool password protects the source code in the drive. If a new program is downloaded to a drive,
the original source code and password protection is erased.
19Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 3 AKDBASICLanguage
3AKDBASICLanguage
This chapter describes the overall structure of an AKD BASIC program and the elements of the
AKD BASIC language. Topics covered are:
l scope
l program structure
l setup parameters
l global variables, constants and aliases
l ‘main’ program, subroutines, functions and interrupt handlers
l language description
l lexical conventions
l identifiers
l data types
l constants
l statements
l built-in functions
l parameters
l expressions
l function invocation
l $include
l arrays and parameter lists
l optimizations
3.1 AKD BASIC Program Structure
3.1.1 Local Variables
The notion of ‘scope’ is a key concept in AKD BASIC programs. By ‘scope’, we mean those
parts of the program in which a particular name is ‘visible’. There are two levels of scope in
AKD BASIC — global and local. Variables (and constant definitions, aliases, etc.) defined
inside a ‘main’ definition, or a subroutine, function, or interrupt handler definition, are considered
to be ‘local’ in scope (visible only within that function).
3.1.2 Global Variables
All other definitions (those occurring outside functions) are considered ‘global’ in scope (visible
inside main, and inside any subroutine, function, or interrupt handler). For example, consider
the following simple AKD BASIC program:
'-------------- Define (dim) Global Variables -
-------
dim i as integer
'-------------- Main Program ------------------
-------
Main
dim i as integer
for i = 1 to 10
print"the cube of "; i; "is "; cube(i)
call increment
next i
End Main
Kollmorgen™ | March 30, 201220
AKD BASIC User Guide | 3 AKDBASICLanguage
'-------------- Subroutines and Functions -----
-------
function cube(i as integer) as integer
cube = i * i * i
end function
sub increment
i = i + 1
end sub
This program prints a table of the cubes of the integers from 1 to 10. The first (global) definition
of ‘i’ is visible inside subroutine ‘increment’, but ‘shadowed’ by the ‘i’ in main and function
‘cube’. The definition of ‘i’ inside ‘main’ is local to ‘main’, and is NOT the same variable as the ‘i’
inside the function ‘cube’, or inside the subroutine ‘increment’. These same scope rules apply to
constant definitions and aliases, as well.
3.2 Program Sections
The major sections of an AKD BASIC program are:
l setup parameter definitions
l global variables, constants, and aliases
l ‘main’ program, subroutines, functions, and interrupt handlers
Although these sections may appear in any order, we recommend that you keep them in the
order shown, or at least, choose a single layout style and use it consistently.
3.2.1 Program Template
The program below is an example of the template generated automatically by WorkBench:
'-------------- Device Params -----------------
------
Params
End Params
'-------------- Define (dim) Global Variables -
------'-------------- Main Program ------------------
-------
Main
End Main
'-------------- Subroutines and Functions ----
--------
'-------------- Interrupt Routines -----------
--------
These sections are described in greater detail in the following paragraphs.
3.2.2 Setup Parameter Definitions
This section of the program defines the setup parameters for drive tuning and configuration. It is
executed immediately upon power-up (if VM.AUTOSTART = 1), before entering main, and
before any interrupts are enabled. The section begins with Param and ends with End Param
21Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 3 AKDBASICLanguage
(this is similar to the format used to define a subroutine or function). The only statements permitted in this section are assignment statements of the form:
<parameter> = <constant expression>
This section can be automatically generated by WorkBench when a New Program is created.
Choose "current drive parameters" to include the connected drive's setup parameters in your
program. If you choose to not include the setup parameters in your program, be sure to save the
setup parameters to the drive to ensure proper drive setup upon power up.
3.2.3 Global Variables, Constants, and Aliases
This section contains variables, constant definitions, and global alias expressions — they
apply everywhere in the program, unless specifically overridden by another declaration at local
scope (inside a subroutine, function, or interrupt handler). Global definitions may be placed
almost anywhere in the program text — between subroutines, before or after ‘main’, and so on.
Global variables, constants, and aliases do not need to be defined before use — the only
requirement is that they be defined at some point in the program text. You may have multiple
instances of the global variables section throughout your program. However, as a matter of
good programming style, we recommend that you keep all global definitions in one place, preferably at or near the beginning of your program.
3.2.4 Variable Definitions
The format of a global variable definition is:
dim a,b as integer, x,y,z as float
dim ia(3,4) as integer
dim s1, s2 as string*80
dim sa(5,2) as string
dim j, k, l as integer NV
Line 1 declares a and b as integers, x,y, and z as floats. Line 2 declares a 3 x 4 array of
integers. Line 3 declares s1 and s2 as strings, each of length 80. Line 4 declares sa as a 5 x 2
array of strings, each with the default length of 32 characters. Line 5 defines 3 integers, j, k, and
l as NV.
In addition, global variables can be specified as ‘NV’ to indicate their values are retained when
power is turned off. All other global variables are automatically initialized when the program
begins (strings are set to empty, and floats and integers are set to 0). There are no restrictions
on the ordering of volatile vs. non-volatile user-variables. For ease of program maintenance,
place all non-volatile variables definitions in a single section at the beginning of the program,
and add new variables to the end of that section.
Names for constants follow the same rules as variable names. ‘Forward definitions’ are
allowed. Circular definitions are detected and reported at compile-time. Although it is not
required, it is convenient to adopt a convention of keeping all constants in UPPER_CASE, so
you can easily distinguish between constants and variables in the program.
Constant definitions are entirely ‘folded’ at compile-time. Feel free to write maintainable constant expressions such as:
The value of AREA is computed at compile-time, so the program does NOT need to compute
this at run-time and the program is easier to maintain if LENGTH changes at some future date.
3.2.6 Alias Definitions
Aliases allow you to define your own names for system resources, such as input / output pins.
The intention is to make it possible for you to use names that are meaningful to you in your particular application. The format of an alias expression is:
alias <name> = <expression>
For example, the following alias defines application-specific uses of input # 1:
alias CONVEYOR_IS_RUNNING = (DIN1.STATE = 0)
alias CONVEYOR_IS_STOPPED = (DIN1.STATE = 1)
if CONVEYOR_IS_RUNNING then
print“running”
else
print“stopped”
An alias is much more powerful than a constant. Constant expressions are computable at compile-time, while an alias has a value that is only known (in general) at the time it is used. Use aliases with care — too much aliasing can make it very difficult for you to understand the
program.
3.3 Main Program, Subroutines, Functions & Interrupt Handlers
These sections share the same fundamental structure:
<section>
<declarations>
<statements>
<section end>
An example of each of these sections follows, with an explanation of key points.
3.3.1 Main Definitions
For main, a typical definition is:
Main
dim i as integer
i = 1
print i
End Main
23Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 3 AKDBASICLanguage
The variable ‘i’ defined above in the ‘dim’ statement is a local variable — it is not accessible to
other functions, and inside ‘main’, its definition overrides any other variable named ‘i’ that might
exist at global scope.
Unlike global variables, local variables MUST be defined at the beginning of the section — they
must appear before any executable statement in main. For example, the following is illegal:
Main
dim i as integer
i = 1
dim j as integer‘this is an error!
j = i
End Main
You may also define local constant definitions and aliases, provided that like local variables,
they appear before any executable statement. Local constant definitions override global definitions of the same name. For example, given the following global definitions,
const N = 1
Main
const N = “Hello, world!”
print N
call sub1
End Main
'-------------- Subroutines and Functions -----
-------
sub sub1
print N
end sub
The program prints to the console:
Hello world!
1
Because the N visible inside main is the constant defined there, while the N visible to sub1 is
the global constant N, whose value is 1.
The main program is the section of your program that is executed immediately after the‘params
section, regardless of its position in the program text. Other functions, subroutines, and interrupt handlers are executed according to the flow of control defined in the program.
main does not accept arguments, and cannot be called from any other subroutine, function, or
interrupt handler.
3.3.2 Subroutine Definition
For a subroutine such as print_sum, a typical definition is:
sub print_sum(i,j as integer)
print i+j
end sub
The arguments to this subroutine are specified as integer variables, and are passed by value any assignments to these variables has no effect on the arguments supplied by the caller. Subroutines are invoked by ‘call’ instructions, as in call print_sum(3,4).
Kollmorgen™ | March 30, 201224
AKD BASIC User Guide | 3 AKDBASICLanguage
3.3.3 Function Definition
For a function such as sum_squares, a typical definition is:
function sum_squares(i,j as integer) as integer
sum_squares = i^2 + j^2
end function
The function above returns a value of type integer. The value of the function is assigned by
assigning to the name of the function, as if it were a variable.
It is not legal to use the function name as a variable name on the left-hand-side of
an assignment - a function name on the leftt-hand-side is always an INVOCATION
of that function.
There must be at least one statement in the function that assigns a value to the function. It is
not possible to detect at compile-time if the statement will actually execute. Functions are
invoked by name, as in print sum_squares(3,4). This is syntactically identical to an array reference.
3.3.4 Interrupt Handler Definition
The Interrupt statment marks the beginning of an Interrupt Service Routine. The Interrupt Service Routine is defined by a program structure resembling a subroutine. The interrupt feature permits execution of a user-defined subroutine upon receipt of a hardware interrupt signal or a predefined interrupt event.
Interrupts are triggered by pre-defined events or external hardware sources. The interruptsource-name and interrupt enable flag are unique for each interrupt source. For a list of interrupt
sources see Interrupt {Source}.
Receiving an interrupt will suspend program execution and the interrupt service routine will be
executed. Then program execution will resume at the point that it was interrupted.
Interrupts are enabled (or disabled) by setting (or clearing) the associated interrupt enable flag.
Interrupts are disabled until explicitly enabled. After an interrupt is triggered it is automatically
disabled until it is enabled again in your program.
Main
DRV.TIME = 0
INTR.DIN1LO = 1 'enables interrupt
while 1
pause(0.5)
DOUT1.STATEU=0 : Pause(0.005):DOUT1.STATEU=1
wend
end main
'the following interrupt defines what occurs
for interrupt DIN1LO
InterruptDIN1LO
print"I'm awake"
IfDRV.TIME > 10 then
print"OK. That's it."
else
INTR.DIN1LO = 1 're-enables interrupt
end if
End Interrupt
25Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 3 AKDBASICLanguage
The interrupt is re-enabled by the statement INTR.DIN1LO = 1. A similar statement must be
executed once before the interrupt is serviced. It is a run-time error to attempt to enable an interrupt for which no handler is defined.
Interrupt handlers do not return values and cannot have arguments. They declare local variables, constants, and aliases. Interrupt handlers are invoked when the AKD hardware detects
that the designated interrupt condition is satisfied (provided that the interrupt is enabled).
Interrupts are triggered by pre-defined events or external hardware sources. The interruptsource-name and interrupt enable flag are unique for each interrupt source.
Receiving an interrupt will suspend program execution and the interrupt service routine will be
executed. Then program execution will resume at the point that it was interrupted.
Interrupts are enabled (or disabled) by setting (or clearing) the associated interrupt enable flag.
Interrupts are disabled until explicitly enabled. After an interrupt is triggered it is automatically
disabled until it is enabled again in your program.
3.4 Language Definition
3.4.1 Lexical Conventions
AKD BASIC is case-insensitive. String literals are not modified, but all other text is treated as if
it were entered in upper case. This means that the identifiers spin, Spin, and SPIN all refer to
the same entity.
3.4.2 Identifiers
Identifiers are alphanumeric and must start with an alphabetic character or underscore. In addition, they may include the underscore character (‘_’) and dollar sign (‘$’). Identifiers denote variables, functions, subroutines, and statement labels, symbolic constants, and aliases.
Identifiers are a maximum of 40 characters. User-defined identifiers may not include the period
(‘.’). Use of a longer identifier is a compile-time error.
Although both forms are accepted for compatibility, the latter form is preferred. Although AKD
BASIC is case-insensitive, we recommend that you adopt a consistent naming convention,
such as Move.Acc, and avoid having Move.acc, move.acc, and move.Acc in the same program.
3.4.3 Data Types
The pre-defined types are INTEGER, FLOAT, and STRING. LONG is used for INTEGER.
INTEGER variables are 32-bit signed integers. FLOAT variables are IEEE single-precision
floating point numbers. STRING variables are represented internally as a maximum length, a
current length, and an array of ASCII characters (can contain null characters).
When a FLOAT result is assigned to an INTEGER variable, or when a FLOAT argument is
used where an INTEGER is expected, the value is coerced to an integer before use. Coercion
from FLOAT to INT always rounds to the nearest integer. For example:
1.2 rounds to 1
1.7 rounds to 2
-1.2 rounds to –1
-1.7 rounds to -2
Scalar INTEGER and FLOAT coercion is automatically provided for function arguments. When
passing ARRAYS as arguments, the types must match exactly because coercion is prohibitively expensive at run-time.
Kollmorgen™ | March 30, 201226
AKD BASIC User Guide | 3 AKDBASICLanguage
String assignment is checked at run-time. An attempt to copy a string to a destination too small
results in a run-time error. String indexing is 1-origin. For example, mid$(“abc”,1,1) returns the
string, a.
STRING variables have a firmware-imposed maximum length of 230 characters and a default
maximum length of 32 characters. They may be assigned a different maximum length by
declaring them to be of type STRING*n where n is a positive integer between 1 and 230 (inclusive).
Declare arrays of the pre-defined types. Arrays have a maximum rank of four dimensions. The
upper-bound of each dimension has no compiler-defined limit. However, because of the limited
data space of the controller, there is a logical upper-bound that depends on the controller model.
Array indexing is 1-origin. The indices in each dimension range from 1 to the upper-bound of the
dimension. Every reference to an array element is checked at run-time. Any attempt to reference beyond the bounds of the array causes a run-time error. New types cannot be defined.
3.4.4 Literal Constants
String constants begin and end with the double-quotes (‘"’). They cannot extend past the end of
the input line. Any printable ASCII character appears in a string constant. An attempt to generate a string literal with non-ASCII characters causes a compile-time error. No check is made
to verify that non-ASCII strings are not created at run-time, so avoid doing so.
3.4.5 Decimal Integer Constants
Decimal integer constants are a string of decimal digits with no decimal point. A leading ‘-’ sign
is optional and is parsed as a unary minus. For example:
1
-1
314159
are all valid decimal constants.
3.4.6 Hexadecimal Constants
Hexadecimal constants are denoted by a leading &H or &h, and cannot have a sign or decimal
point. Hexadecimal constants are composed from the set [0-9A-Fa-f]. Upper- and lower-case
may be mixed.
For example:
&h00ff
&HFF00
&H1234abcd
are all valid hexadecimal constants. Octal and binary constants are not supported.
3.4.7 Floating-Point Constants
Floating-point constants are specified in fixed-point or mantissa-exponent notation. A floatingpoint constant consists of one of the following.
are all valid floating point constants. By design, “.” is not a legal floating-point constant.
3.5 Statements
Statements are separated by a new line (CR-LF) or a colon (‘:’). The statements of the language
are:
3.5.1 Alias
Create an alias for an identifier (not just any identifier). Alias is either a parameter or another
alias. ID must be a legal variable name. You cannot create an alias for an array element.
Like Const definitions, Alias definitions can be made to identifiers not yet defined. Circular definitions are not allowed.
Any duplicate definition of an identifier in the same scope is illegal. However, a local definition
can shadow a definition from the global scope. Using a single identifier to denote two different
objects is NOT allowed (i.e., you cannot have both a label and a variable named all_done).
Like constant, variable, and function declarations, Alias declarations made in the global scope
are imported into all functions (including the main function).
Example:
Alias speed = MOTOR.SPEED‘save some key-
strokes
3.5.2 Call
Call sub[(arg1, arg2, ...)]
sub is the name of a subroutine. The current program counter is saved and sub is invoked.
When sub finishes (by reaching either an exit sub or end sub statement, control is returned to
the statement logically following Call.
A subroutine is essentially a function with no return value. The parameter passing conventions
followed by subroutines are the same as those followed by functions.
3.5.3 Cls
This statement transmits 40 line-feed characters (ASCII code = 10) to the serial port. Cls clears
the display of the console.
3.5.4 Const
const name = x
Declares symbolic constants to be used instead of numeric values. Forward references are
allowed, but circular references are not supported.
'supported
const x = y + 2
Kollmorgen™ | March 30, 201228
AKD BASIC User Guide | 3 AKDBASICLanguage
const y = 17
'unsupported
const x = y + 2
const y = x - 2
Like alias, variable, and function declarations, Const declarations made in the global scope are
imported into all functions (including the main function).
3.5.5 Dim
Dim var1 [, var2 [...]] as type [NV]
All variables must be declared. Local variables must be declared in the function before use.
The NV specifier is used on a Dim statement in the global scope.
Variables in the global scope are automatically imported into functions and subroutines. Variables in function scope (including inside the main function) are not accessible in other functions.
Arrays cannot be assigned directly.
'This is not allowed
dim x(5), y(5) as integer
x = y
'Instead, a loop is needed:
dim x(5), y(5), i as integer
for i = 1 to 5
next i
3.5.6 Exit
Exit {{Sub|Function|Interrupt|For|While}]
Exits the closest enclosing context of the specified type. It is a compile-time error to EXIT a
construct not currently in scope.
3.5.7 For…Next
For loop_counter = Start_Value To End_Value [Step increment]
...statements...
Next
If step increment is not specified, uses 1 as the step increment. If step increment is positive,
continues to the value of End_Value. If step increment is negative, continues to the value of var
= limit.
The loop index variable must be a simple identifier, not an array element or a parameter and
must be a numeric variable (integer or float).
x(i) = y(i)
for var = init to limit step delta
stlist
next var
Substantially more efficient code is generated if delta is a constant (i.e., the default value of 1 is
used, or specified as an expression that is evaluated at compile-time).
29Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 3 AKDBASICLanguage
3.5.8 Function
Function function-name [(argument-list)] as function-type
...statements...
End Function
On function entry, all local variable strings are “” and all numeric locals are zero (including all elements of local arrays). If the function takes no arguments, omit the argument-list. An empty
argument-list is illegal. The value returned from the function is specified by assigning an identifier with the name of the function.
Example:
function cube(x as float) as float
cube = x * x * x
end function
Arguments are passed by value. Arrays can not be returned by a function. Arrays passed to a
function are passed by value.
If the return value is not set, a runtime error condition is generated (caught with ON ERROR).
Array actuals must conform with formals to the extent that they have the same number of
dimensions, and EXACTLY the same type. The size of each dimension is available to the function through the use of local constants that are bound on function entry.
Example:
function sum(x(n) as integer) as integer
dim i, total as integer
sum = 0
for i = 1 to n
next
sum = total
end function
This function exploits the fact that the variable N is automatically assigned a value when the
function is called and the value is the extent of the array passed on invocation. N is a read-only
variable in this context. Attempts to write to N cause compile-time errors.
The local variable, total is automatically initialized to 0 upon function entry.
3.5.9 GoTo
GoTo label
A program can only GoTo a label in the same scope. A GoTo may jump out of a For or While
loop, but not INTO one.
3.5.10 If…Then…Else
if condition1 then
...statement block1...
elseif condition2 then
...statement block2...
else
...statement block3...
end if
total = total + x(i)
Kollmorgen™ | March 30, 201230
Loading...
+ 476 hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.