Calibration Script


Gage Control Script can be used to make special adjustments to the calibration data.

 

A default calibration script can be entered into the text box in the Calibration Settings page.

If this box is empty only the normal calibration saving will take place.

 Or if that gage record has field "calscript" or "calcsriptmemo" with something in it, that script will be used instead. Field "calscript" or "calscriptmemo" has to be a memo field if you are going to be using more than a one line script. If only using a one line script it could be a string field. Use "calscriptmemo" if you want to have a dropdown editor capability in the grids.

The calibration script is performed after all normal saving the calibration processing takes place.

 

Gage Control Script Basic is 90% compatible with MS GWBasic and QBasic, 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 style Basic programs 

 

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
Rounding 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(string$,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$(filename$) 
SAVETEXT$(filename$) 
COPYTEXT$($) 
PASTETEXT$($) 
FINDFILE$(directory$,ext$)
FINDDIR$(directory$,filter$)

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
Returns a list of files in the directory (dir,extension)
Returns a list of directories in a string.

 

 

 Miscellaneous functions:

 

PAUSE(n)
MESSAGE($)

BEEP()

DOEVENTS()

Suspend execution for n seconds
Show a message in a dialog window.

Makes Windows sound.

Can use in a long running loop to prevent user interface from freezing.

 

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 Database Functions

 

 

 

 

 

For Current GageMaster table row:

 

setfield(filedname$,value$)

Puts string value in field. Is converted to field type.

setfield("suffix","004")

getfield$(fieldname$)

gets value from field converted to string.

a$=getfield$("suffix")

setdatefield(fieldname$,date)

puts date value in date field.

setdatefield("duedate",n)

You could use setfield to put in a date if you have a string like "12/21/2011" but setdate field is for when you have the date stored as a number. You have to store it as a number if you are doing calculations on it.

getdatefield(fieldname$)

gets date value from field.

n=getdatefield("duedate")

You could use getfield$ to get a string representation of the date but using this will avoid problems with different date formatting when you use it in calculations.

setnumfield(fieldname$,value)

Put a value in a number field.

setnumfield("frequency",12)

getnumfield(fieldname$)

Get value from a number field.

n=getnumfield("frequency")

You could get the value as a string with getfield$ but you would use this if you needed to make calculations with it.

Not related to current row:

 

incdate(date, dayincrement, monthincrement, yearincrement)

returns the incremented date.

n=incdate(date,-1,2,1)

The increment values can be negative so you can subtract from the date.

It does the three items in order. First it increments the days, then from that it increments the months, then from that it increments the years.

This takes into consideration number of days in a month and leap years too.

now()

returns the current date as a number.

datestring$(date)

returns a string of the date.

a$=datestring$(n)

You would use this when you need to display the date or add it to another string.

select(sql_command$)

Select a set of records. Returns the number of records selected.

select("select * from gagemaster where suffix='001'")

This selects a set of records you can work with. This is not the same record set that is displayed in the grids.

selectnext()

Goes to next record in the Selected record set.

Returns the row number it is on. So when it returns the same number as was returned with the select command you know you are at the end of the list.

n=select("select * from gagemaster where suffix='003'")

if n<1 then end

setselect("suffix","004")

repeat

  rownum=selectnext()

  setselect("suffix","004")

until rownum>=n

dosql(sql_command$)

Use for SQL commands that don't return a selection set.

dosql("UPDATE gagemaster SET suffix='002' WHERE EXISTS ( SELECT suffix  FROM gagemaster WHERE suffix = '001'")

Use this for update etc. commands.

refresh()

Refreshes the display grids. You can use this after you make changes to the database if needed.

clearprint()

Clears any PRINT text from the buffer. If you don't use this at the beginning of the script the earlier print output will still be in the buffer and you will be adding on to them.

saveprint(filename$) 

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

a$=getfield$("duedate")

print "Duedate=" ; a$

saveprint("test.txt")

executefile(filename$,param$)

Runs an executable file. Parameters for the program are optional.

Line$=getfield("gagesn")
if instr(line$,"R")>0 then
  executefile("C:\MyProgram.exe","/M")
endif

Scan$()

Returns the string from the Barcode edit window.

setpage(number)

Switches to the tab. Overdue tab=0;
Find Gage tab=1; Edit Gage tab=2;
Calibration tab=3; Checkin tab=4;

locaterow(field$,value$,grid)

Finds row in grid and highlights it.
locaterow("gagesn","1234",0)

Find Gage grid=0; Overdue grid=1;
Checkin grid=2;

Returns -1 when found row, 0 when not.

printreport(filename$)

If report filename has no path then it will use the User Data Path.

previewreport(filename$)

If report filename has no path then it will use the User Data Path.

setselect(fieldname$,value$)

Sets a field value in the current row that was selected using the Select command.

select("select * from gagemaster where suffix='003'")

setselect("suffix","004")

getselect$(fieldname$)

Retrieves the value in the field.

getglobalnum(num)

Retrieves the stored global number value.

setglobalnum(num,value)

Stores the global number value.

getglobal$(num)

Retrieves a stored global string.

setglobal$(num,value$)

Sets a global 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"