Details
From DVD-lab
Advanced Authoring - LabTALK - Details of Core language
This page describes in greater detail the core of the BASIC language used in
LabTALK. Again it is not a tutorial about programming and it assumes users have some knowledge about programming. It is here more for reference and in form of examples. If you don't know what a for-next loop does then it won't help you
to know its syntax.<img src="images/triangle.gif" alt="" width="21" height="22" border="0">Loop: for - next
The loop expects to be counting only upwards and its syntax is as in the example below
for i = 1 to 10
print i
next i
You can exit from loop anytime by simply overwriting the loop variable value
for i = 1 to 10
if (i > 4) then
i = 10
next i
loops can be also nested
for x = 1 to 10
print x,",",y
next x
<img src="images/triangle.gif" alt="" width="21" height="22" border="0">Condition: if -then- else -endif
A typical basic condition using if - then
a = 10 b = 20
endif
You have to always close if with endif!
a = 40 b = 20
print"true!"
else
endif
Inside the condition you can use these boolean operators and these operands:
| Operand | Syntax example | Description |
| & | if (a ==1 & b==2) then | AND |
| if (a ==1 | b==1) then | OR | |
| == | if (a ==1) then | is equal |
| != <> | if (a != 1 ) then if (a <> 1 ) then | is not equal |
| <= | if (a <=1 ) then | if less or equal |
| < | if (a < 1 ) then | if less |
| >= | if (a >= 1 ) then | if bigger or equal |
| > | if (a > 1 ) then | if bigger |
<img src="images/triangle.gif" alt="" width="21" height="22" border="0">Printing to screen: print, trace, print msg
Printing values of variables is done with print command. There are few flavors of it, each has the same syntax:
| Command | How it works |
| Output to Output window if run from within lab-TALK script editor If run directly (drag-and dropping) it will show a pop=up window | |
| trace | Output only to Output window. If run directly, nothing will be print. Good for debugging |
| print msg | like print, but it will always pop-up message and never print to output window. The pop-up window will have "Continue Script?" thext added that allows to break the script run. |
The syntax of all print commands is simple. Consider the sample below:
a = 10
b = " Hello"
print"just text"
print a
print a+10
print"Variable:", a
print"Variable:", a ," String", b
<img src="images/triangle.gif" alt="" width="21" height="22" border="0">Input command
This command is used to popout an input dialog where user can change one or more variables.
A simple usage is this:
a = 10
input"Set variable a", a
When you run the script a labTALK input dialog will be shown:
<img src="images/ltinput.gif" alt="" width="344" height="240" border="0">
Obviously there places for more variables on the input dialog and indeed, you can use:
a = 10
b = "string"
input"Set variable a", a, "Set String", b
Running this will show:
<img src="images/ltinp2.gif" alt="" width="286" height="45" border="0">
Special input commands.
The input dialog can also modify the way how you enter the data.
Checkbox
This is done by setting CHECK: inside the string
a = TRUE
input"CHECK:Set checkbox", a
<img src="images/ltinput3.gif" alt="" width="309" height="23" border="0">
File box with browse button
This is done by setting FILE: inside the string
a = "C:\\myfile.txt"
input"FILE:Set file", a
<img src="images/ltinput4.gif" alt="" width="305" height="26" border="0">
Color box with color selection button
This is done by setting COLOR: inside the string
a = RGB(255,0,0)
input"COLOR:Set color", a
<img src="images/ltinput6.gif" alt="" width="301" height="26" border="0">
Option box (combo box)
The options follow after ':' and are divided by '|'. The variable is from 0 ...number of options -1
a = 1
input"Select Option:Option 1|Option 2|Option 3", a
In the above example, the return value (in "a") will be 0, 1 or 2.
<img src="images/ltinput5.gif" alt="" width="301" height="30" border="0">
A variable bCancelInput will become TRUE if user press Cancel on the input dialog.
A code below will exit the script if user press Cancel:
input "COLOR:Select Color ", color1
//allow cancel
ifbCancelInputthen
endif
<img src="images/triangle.gif" alt="" width="21" height="22" border="0">end - finish script
The command end will simply finish the script
ifbCancelInputthen
end
endif
It is not necessary to put "end" at the end of script, but if you have subroutines, you have to put end before them, see gosub below.
<img src="images/triangle.gif" alt="" width="21" height="22" border="0">goto - go to a label
The label is a number. Any number will do. Please do not confuse the labels with line numbers. It has nothing to do with them.
10 input"Value 1 or 2", a
if (a==1) then
endif
if (a==2) then
endif
print"I can understand 1 or 2"
goto 10
100 print msg"You entered One"
end
200 print msg"You entered Two"
end
The program will loop untill you enter 1 or 2 then it will display the message.
The labels don't have to be in sequential order, but it makes the program look more logical. (The numerical labels come from the time of first computers when every line written in BASIC had its own number, but we no longer use that so only the labels remained)
<img src="images/triangle.gif" alt="" width="21" height="22" border="0">Gosub - go to subroutine
Subroutines in BASIC have to be at the very end of the script and must be labeled by label number (this has nothing to do with line numbers). Returning from a subroutine is done with the return command.
gosub 100
print"2"
end
100 print"subroutine"
return
The printed result will be:
1
subroutine
Note the end command before the subroutine will finish the script. It is required to have an "end" statement before you write any subroutines.
