Your company's Logo

   


Filter Script Basic is 90% compatible with MS GWBasic and QBasic(TM), with some Pascal extension like While, Repeat, Break, Continue, which let you write programs without labels and Goto instructions. Numeric labels are supported for backward compatibility with old Basic programs

More Filter Script Info

This Basic Script supports Numbers and Strings.

Built-in Basic Functions
 
Numeric functions:
 
ABS(n)
LN(n) 
LOG10(n)
LOG2(n) 
EXP(n) 
RND() 
RND(n)
INT(n) 
FIX(n)
ROUND(n)
FRAC(n)
SQR(n)
SGN(n) 
SIN(n)
COS(n) 
TAN(n)
ASIN(n)
ACOS(n)
ATAN(n)
ATAN2(n,m) 
SINH(n)
COSH(n)
TANH(n)
ASINH(n)
ACOSH(n)
ATANH(n)
DEGTORAD(n)
RADTODEG(n)
ASC($) 
LEN($)
VAL($)
Absolute value 
Natural logarithm, base e 
Logarithm, base 10 
Logarithm, base 2 
Exponential 
Random number in the range 0..1
Random number in the range 0..n 
Integer part of n 
Integer part rounded toward zero
Roundation of n 
Fractional part of n 
Square root 
Sign of n, +1 0 -1 
Sine of number, radians
Cosine 
Tangent 
Inverse sine 
Inverse cosine 
Inverse tangent 
Inverse tangent of n/m with right quadrant
Hyperbolic sine 
Hyperbolic cosine 
Hyperbolic tangent 
Inverse hyperbolic sine 
Inverse hyperbolic cosine 
Inverse hyperbolic tangent 
Degrees to radians conversion 
Radians to degrees conversion 
Ascii code of char 
Length of string 
String to number conversion
 
 
 
 String functions:
 
LCASE$($)
UCASE$($)
LTRIM$($)
RTRIM$($)
CHR$(n)
STR$(n)  
HEX$(n)
MID$($,n,[n])
LTAB$($)
RTAB$($)
LEFT$($,n) 
RIGHT$($,n)
INSTR($,substring) 
Lowercase conversion
Uppercase conversion 
Left blanks deletion 
Right blanks deletion 
Ascii to char conversion 
Number to string conversion
Number to hexadecimal 
Substring extraction 
Left insertion of a Tab 
Right insertion of a Tab 
Left part of a string 
Right part of a string
Returns position of substring
 

 

 
 String functions, Multi Rows:
 
COUNT($)
OPENTEXT$($) 
SAVETEXT$($) 
COPYTEXT$($) 
PASTETEXT$($) 
FINDFILE$($,$)
FINDDIR$($,$)
Count rows in a multi-row string
Open a text file into a string
Save the string as a text file
Copy the string to the clipboard 
Paste text from clipboard into the string
Get a list of files in the directory (dir,extension)
Get a list of directories
 
 

 
 Miscellaneous functions:
 
PAUSE(n)
MESSAGE($).
Suspend execution for n seconds 
Show a message in a dialog window.
 

 

Reserved words

if 
end
for
goto
local
print
endfunc
or
mod
not
step
while
input
endwhile
to
cls
else
break
gosub
repeat
continue
and 
rem 
then 
endif 
until
return 
function

 

True = -1
False = 0

 

 Built-in CNC Functions    
addspaces()
cancel()
changev(address,oldvalue,newvalue,format)

closefile()
createfile(filename)
currentlinenumber()
executefile(filename,param)
firstline()
front(string)
hasaddress(address)
getvalue(address)
getglobalnum(index)
getglobal$(index)
getlineindex$(index)

gotoline(index)
insertline(string)
ioline$()

lastline()
linecount()

offset(address,value)
openfile(filename)
output(string)

punchleader(inches)
punchmanread(string)

remove(string)
rear(string)
rotate(angle)
stripcomment()
stripspaces()
setline(string)
scale(address,value)
setglobalnum(index,value)
setglobal$(index,string)
saveprint(filname)
sendxon()
sendoff()
setlineindex$(index,string)
stop(string)
sendfile(filename)
wait(milliseconds)
writetofile(string)

 
   

Comments:

REM this is a comment
' and this is too
' but shorter


  1# Example: (Pascal-like, recommended style)     
for a = 1 to 10 
print "Hello"  
  if a > 5 then break 
next 
print "the end" 

2# Example: (old Basic style) 

10 for a = 1 to 10
20 print "Hello" 
30 if a > 5 then goto 50 
40 next a 
  50  print "the end" 

Loop instructions

Basic Script supports three kinds of loop instructions.
For, While and Repeat
The easiest way to understand a Loop instruction is to look at an example.
The following program prints the numbers 1 to 10, "a" is the control variable: 

FOR a = 1 to 10 
  PRINT a
NEXT a 

The BREAK instruction:
terminates instantly a cycle, so in this case the cycle stops when "a" becomes greater than 5. 

FOR a = 1 to 10 
PRINT a 
  IF a>5  then BREAK
NEXT a 

The CONTINUE instruction: acts as a NEXT instruction; the variable "a" is incremented and a new iteration is started immediately. 

FOR a = 1 to 10 
PRINT a 
IF a>5 then CONTINUE 
  PRINT "hello"
NEXT a  

FOR-NEXT instruction:
The complete syntax for this command is:

FOR <variable> = <expression> to <expression> [step <constant>]
...
...
NEXT [<variable> (ignored)]
examples:  
FOR angle = 1+ASIN(0.4) to 1+ASIN(0.75) step 0.1 
  PRINT angle 
NEXT 
FOR y = 1 to 200 
  FOR x = 1 to 320 
   s = s + x*y 
   NEXT 
NEXT  

REPEAT-UNTIL instruction: 
This instruction repeats a series of instructions until the condition is True. The block begins with the REPEAT command and ends with the UNTIL command followed by the condition that is evaluated.
Example:

a = 1
REPEAT
PRINT a
  a = a+1
UNTIL a>10 

The Repeat instruction evaluates the condition at the end of the loop, this means that the instructions inside the loop are executed at least once. The Break and Continue instructions can be used in REPEAT-UNTIL cycles just like in the FOR-NEXT cycles.                                                                                     


WHILE-ENDWHILE instruction: 
This instruction evaluates a condition at the beginning of the loop. If the condition is false then the cycle stops and execution continues after the Endwhile instruction. 
Example:

a = 1 
WHILE a <= 10 
 PRINT a 
 a = a+1 
ENDWHILE 

Since the While command evaluates the condition at the beginning of the loop, the instructions inside the loop may be also executed never. The Break and Continue instructions can be used in WHILE-ENDWHILE cycles just like in the FOR-NEXT cycles.


Strings 
A string variable contains text. This text may be a single row or a multi-line text. The maximum theoretical size of a string variable is 2 Gbyte.
Example:

 a$ = "Hello" + "World" + "!"

The value of the variable "a$" is now "HelloWorld!" 
String variables are used with operators to perform string expressions and are used with some functions to Open and Save data from text files. 
A single row of a multi-line string con be read using square brackets, example:

if a$ contains:

" This is a
text placed on 
three rows "  
b$ = a$[2]

Now b$ contains: "text placed on" 
 


Numbers

A numeric variable contains a number. The number is internally represented by a floating point value with double precision (64 bit, 15 significant digits).

Numeric variables are used with operators to perform numeric expressions and are used as counters in loop  instructions.


Jump instructions

The following instructions (Goto, Gosub, Return) are supported only for compatibility with Basic.
They cannot be used inside Functions.

Goto instruction: 
This instruction jumps at the given label.
Example:

10 if a > 5 then GOTO 30
20 print "a <= 5" 
30 print "Script ended"  
Gosub - Return instructions:  
They were used to make subroutines. Now it's better to define a Function.  
Example:
10 x = 3 : y = 6
20 GOSUB 100 
30 print "Result:" ; r 
40 end 
100 r = sqrt(x^2+ y^2) 
110 RETURN 

Basic functions

A function is defined as set of instructions that computes and returns a value.

The result can be discarded (like C and Delphi) or simply not returned, making it a procedure. Local variables can be defined to support recursive functions. 

Syntax:

Function <Name> ( parameters ) [ Local <local variables> ]
  ... 
  [Return <result>] 
  ...
Endfunc 
Examples:  
FUNCTION sum(a,b)
  return a+b
ENDFUNC 
FUNCTION intpower(a,b) LOCAL t,r
  r=1 
  for t = 1 to b
   r = r * a
  next 
  return r
ENDFUNC 
FUNCTION hello$(a$)
  return "Hello to you " + a$
ENDFUNC 
  

Basic fully supports recursive functions, example:

FUNCTION factorial(n)
  if n <= 1 then return 1 
  return n*factorial(n-1)
ENDFUNC 

Conditional instructions

The IF-THEN instruction evaluates a logical expression and determines the flow of the program based on the result of that expression.

Examples of logical expressions:

a > 5 and b > 5
a >= 3 or not b <> 5 and b+3 = c  
Precedence of operators:

Higher precedence:  

< , > , <= , >= , <> , =
NOT 
AND 
OR 

Lower precedence.

Syntax:

IF <logical expression> THEN
... 
... 
[ELSE] 
... 
... 
ENDIF 
Compact Syntax:
IF <logical expression> THEN <instruction> : <instruction> ...

IF instructions can be nested without limits; the ELSE part is optional and is not allowed in the compact syntax. 
Examples:

IF a < 0 and a > -10 THEN print "A was a small negative number": a = -a
IF a >= 0 THEN
 print a 
 IF a = 12 THEN print "A prefect number !" 
 IF a > 1000 THEN
  print "What a big number"
 ENDIF
ELSE
 print "Negative numbers not allowed!"
ENDIF 

Identifiers

Identifiers denote variables and functions.
An identifier can be of any length, must begin with a letter and can't contain spaces.

String identifiers denote string variables and string functions.
The last character must be $       

examples of valid identifiers:

counter , temp , pix , n , n2 
name$ , address2$ , filename$ , a$ 

PRINT

Since there is no window to print to in Filter Script, the print function prints to buffer that can be saved to a file.
See SavePrint function.

Print [ expression [, expression] [; expression] ]  

Description: 
Every expression must be separated by a semicolon or comma; if semicolon is used then no spaces are added between the writings. If comma is used then a TAB separator is added between the writings. Numbers are always printed preceded by a space.
Example: 

PRINT "Some math" ; 3+5 ; 4*4*4 ; sin(2.5)  

INPUT Shows a dialog window where the user can enter data.           

Input [ <Question> , ] variable

Description: 
Use this function to ask the user for input values.
If the user doesn't click the OK button then zero or an empty string is returned.
Example:

INPUT "How old are you ?", a
INPUT "Your name ?", n$ 
PRINT n$ ; " is"; a 

Operators

Operators are classified as arithmetic operators and string operators. 

Precedence: 
Operators with higher precedence are performed before operators with low precedence.
Operators with equal precedence are performed from left to right. 

Numeric operators
Numeric operators apply in numeric expressions, Basic supports the following operators: 

+
-
*
/
^
?>
?<
MOD
Addition
Subtraction
Multiplication
Division
Power
Maximum
Minimum
Modulo

Higher precedence: 

( , )
- (unary) 
 ^ 
 * , / , MOD 
 + , - , ?> , ?<  

Lower precedence.

Examples:  

12 + 15 = 27
12 - 4 = 8
2 ^ 8 = 256
7 * 5 = 35
10 / 4 = 2.5 
18 MOD 8 = 2
5 ?> 3 = 5 
8 ?< 2 = 2 

String operators 
String operators apply in string expressions, Basic supports the following operators: 

+ Addition
/ Addition with New Line
- Deletion 

Precedence: 
String operators have the same precedence and are evaluated from left to right. 
Examples:  

"Hello" + "World" = "HelloWorld"
"Hello" - 2 = "Hel" 
"Hello" / "World" = 
"Hello
World"   

Back

 

 

 

 

 

      
      
 

Copyright ©2011 i-Logic Software. email: support@i-logic.com