Basic Syntax
ArtSong’s Basic Script Editor and Algorithm components execute scripts written in Basic syntax. Current Basic syntax supports:
sub .. end and function .. end declarations
byref and dim directives
if .. then .. else .. end decision making
for .. to .. step .. next loop constructor
do .. while .. loop and do .. loop .. while loop constructors
do .. until .. loop and do .. loop .. until loop constructors
* , / , and , + , - , or , not , <> , >= , <= , = , > , < , div , mod , xor , shl , shr operators
try .. except and try .. finally exception handling blocks
select case .. end select decision making
array constructors (x:=[ 1, 2, 3 ];)
exit statement
access to object properties and methods (ObjectName.SubObject.Property)
Script structure
Script structure consists of two different code sections: 1) a first section containing procedure and function declarations and 2) a main block. Both sections are optional, but at least one should be present in script. If both sections are present the ‘procedure and function’ section should precede the ‘main’ section. The ‘main’ section does not need to be inside a begin..end code block and it may just consist of a single statement. Script execution begins in the main section.
Examples
SCRIPT 1:
SUB DoSomething CallSomething END SUB CallSomethingElse
SCRIPT 2:
CallSomethingElse
SCRIPT 3:
FUNCTION MyFunction MyFunction = "Ok!" END FUNCTION
As in common basic, statements in a single line can be separated by ":" character.
Identifiers
‘Identifier’ refers to the names that we use in scripts to represent variables, functions, procedures, etc. The rules for naming follow the common naming practices for common Basic : names must begin with an alphabetic character (a..z or A..Z) or underscore (_), and can be followed by alphanumeric chars (a..Z and 0..9) or underscore '_' char. Names cannot contain any other characters or spaces.
Valid identifiers:
VarName _Some V1A2
Invalid identifiers:
2Var My Name Some-more This,is,not,valid
Variables
Variables are named ‘data’ storage areas used to hold values during script execution. ArtSong requires variables to be declared prior to use; if you do not declare variables you will receive a compile error.
Declare variables using the Dim keyword. Multiple variables can be declared on the same line. It is important to note that all variables have local scope; they can only be ‘seen’ within the code block they are defined in.
Example Variable Declarations
// declares one variable named ‘myVariable’ Dim myVariable; // declares three variables Dim myA, myB, myC;
Variables having global scope, (can be seen from any code block), must be defined before the FUNCTIONS section.
Dim myA, myB, myC; FUNCTIONS Code Block MAIN Code Block
Variables are actually implemented as Variants by the scripting engine and can be used to store integer or floating point numbers, text strings, or object references.
Examples
SCRIPT 1:
SUB Msg; DIM S; // declares a variable which can // only be used in this subroutine S = 'Hello world!' ShowMessage(S) END SUB
SCRIPT 2:
DIM A A = 0 A = A+1
SCRIPT 3:
DIM S S = 'Hello World!' ShowMessage(S)
SCRIPT 4:
GLOBALS A // A can be accessed from both // code sections below SUB DoSomething A = 32 END SUB ShowMessage(A) DoSomething // assigns a value to A ShowMessage(A)
Assignment Statements
Assign statements are used to assign a value or expression result to a variable or object property. Assign statements are built using the assignment operator “=".
Examples:
myVar = 2 myOtherVar = 2.345 Button.Caption = 'This ' + 'is ok.';
Character Strings
Character (or text) strings are declared using the double quote (“) character.
A = “This is a text string”
Concatenate strings using the ‘+’ operator.
B = “Text “ + “concat”
String characters can be indexed using "[" and "]" chars. For example, if Str is a string variable, the expression Str[3] returns the third character in the string denoted by Str, while Str[I + 1] returns the character immediately after the one indexed by I.
Examples:
MyChar = MyStr[2] MyStr[1] = “A”
Comments
Comments can be inserted inside script. You can use ' chars or REM. Comment will finish at the end of line.
» |