Details

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. 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 print  i <font color=blue face="Courier New,Courier,Monaco">if <font face="Courier New,Courier,Monaco"> (i &gt; 4) <font color=blue face="Courier New,Courier,Monaco">then <font face="Courier New,Courier,Monaco"> i = 10 <font color=blue face="Courier New,Courier,Monaco">endif <font face="Courier New,Courier,Monaco"> <font color=blue face="Courier New,Courier,Monaco">next <font face="Courier New,Courier,Monaco"> i loops can be also nested  <font color=blue face="Courier New,Courier,Monaco">for <font face="Courier New,Courier,Monaco"> x = 1 <font color=blue face="Courier New,Courier,Monaco">to <font face="Courier New,Courier,Monaco"> 10 <font color=blue face="Courier New,Courier,Monaco">for <font face="Courier New,Courier,Monaco"> y = 1 <font color=blue face="Courier New,Courier,Monaco">to <font face="Courier New,Courier,Monaco"> 10 <font color=blue face="Courier New,Courier,Monaco">print <font face="Courier New,Courier,Monaco"> x,&quot;,&quot;,y <font color=blue face="Courier New,Courier,Monaco">next <font face="Courier New,Courier,Monaco"> y <font color=blue face="Courier New,Courier,Monaco">next <font face="Courier New,Courier,Monaco"> 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  <font face="Courier New,Courier,Monaco">a = 10 b = 20 <font color=blue face="Courier New,Courier,Monaco">if <font face="Courier New,Courier,Monaco"> (a+b==30) <font color=blue face="Courier New,Courier,Monaco">then <font face="Courier New,Courier,Monaco"> <font color=blue face="Courier New,Courier,Monaco">print <font face="Courier New,Courier,Monaco"> <font color=FF0000 face="Courier New,Courier,Monaco">&quot;true!&quot; <font face="Courier New,Courier,Monaco"> <font color=blue face="Courier New,Courier,Monaco">endif <font face="Courier New,Courier,Monaco"> You have to always close if with endif! <font face="Courier New,Courier,Monaco">a = 40 b = 20 <font color=blue face="Courier New,Courier,Monaco">if <font face="Courier New,Courier,Monaco"> (a+b==30) <font color=blue face="Courier New,Courier,Monaco">then <font face="Courier New,Courier,Monaco"> <font color=blue face="Courier New,Courier,Monaco">print <font face="Courier New,Courier,Monaco"> <font color=FF0000 face="Courier New,Courier,Monaco">&quot;true!&quot; <font face="Courier New,Courier,Monaco"> <font color=blue face="Courier New,Courier,Monaco">else <font face="Courier New,Courier,Monaco"> <font color=blue face="Courier New,Courier,Monaco">print <font face="Courier New,Courier,Monaco"> <font color=FF0000 face="Courier New,Courier,Monaco">&quot;false!&quot; <font face="Courier New,Courier,Monaco"> <font color=blue face="Courier New,Courier,Monaco">endif <font face="Courier New,Courier,Monaco"> Inside the condition you can use these boolean operators and these operands: b = <font color=FF0000 face="Courier New,Courier,Monaco">" Hello" <font face="Courier New,Courier,Monaco"> <font color=blue face="Courier New,Courier,Monaco">print <font face="Courier New,Courier,Monaco"> <font color=FF0000 face="Courier New,Courier,Monaco">"just text" <font face="Courier New,Courier,Monaco"> <font color=blue face="Courier New,Courier,Monaco">print <font face="Courier New,Courier,Monaco"> a <font color=blue face="Courier New,Courier,Monaco">print <font face="Courier New,Courier,Monaco"> a+10 <font color=blue face="Courier New,Courier,Monaco">print <font face="Courier New,Courier,Monaco"> <font color=FF0000 face="Courier New,Courier,Monaco">"Variable:" <font face="Courier New,Courier,Monaco">, a <font color=blue face="Courier New,Courier,Monaco">print <font face="Courier New,Courier,Monaco"> <font color=FF0000 face="Courier New,Courier,Monaco">"Variable:" <font face="Courier New,Courier,Monaco">, a, <font color=FF0000 face="Courier New,Courier,Monaco">" String" <font face="Courier New,Courier,Monaco">, 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: <font face="Courier New,Courier,Monaco">a = 10 <font color=blue face="Courier New,Courier,Monaco">input <font face="Courier New,Courier,Monaco"> <font color=FF0000 face="Courier New,Courier,Monaco">"Set variable a" <font face="Courier New,Courier,Monaco">, 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:  <font face="Courier New,Courier,Monaco">a = 10 b = <font color=FF0000 face="Courier New,Courier,Monaco">"string" <font face="Courier New,Courier,Monaco"> <font color=blue face="Courier New,Courier,Monaco">input <font face="Courier New,Courier,Monaco"> <font color=FF0000 face="Courier New,Courier,Monaco">"Set variable a" <font face="Courier New,Courier,Monaco">, a, <font color=FF0000 face="Courier New,Courier,Monaco">"Set String" <font face="Courier New,Courier,Monaco">, 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 <font face="Courier New,Courier,Monaco">a = <font color=darkviolet face="Courier New,Courier,Monaco">TRUE <font face="Courier New,Courier,Monaco"> <font color=blue face="Courier New,Courier,Monaco">input <font face="Courier New,Courier,Monaco"> <font color=FF0000 face="Courier New,Courier,Monaco">"CHECK:Set checkbox" <font face="Courier New,Courier,Monaco">, 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  <font face="Courier New,Courier,Monaco">a = <font color=FF0000 face="Courier New,Courier,Monaco">"C:\\myfile.txt" <font face="Courier New,Courier,Monaco"> <font color=blue face="Courier New,Courier,Monaco">input <font face="Courier New,Courier,Monaco"> <font color=FF0000 face="Courier New,Courier,Monaco">"FILE:Set file" <font face="Courier New,Courier,Monaco">, 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  <font face="Courier New,Courier,Monaco">a = <font color=darkred face="Courier New,Courier,Monaco">RGB <font face="Courier New,Courier,Monaco">(255,0,0) <font color=blue face="Courier New,Courier,Monaco">input <font face="Courier New,Courier,Monaco"> <font color=FF0000 face="Courier New,Courier,Monaco">"COLOR:Set color" <font face="Courier New,Courier,Monaco">, 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 <font face="Courier New,Courier,Monaco">a = 1 <font color=blue face="Courier New,Courier,Monaco">input <font face="Courier New,Courier,Monaco"> <font color=FF0000 face="Courier New,Courier,Monaco">"Select Option:Option 1|Option 2|Option 3" <font face="Courier New,Courier,Monaco">, a  In the above example, the return value (in &quot;a&quot;) 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: <font color=blue face="Courier New,Courier,Monaco">input <font face="Courier New,Courier,Monaco"> &quot;COLOR:Select Color &quot;, color1   <font color=008000 face="Courier New,Courier,Monaco">//allow cancel   <font face="Courier New,Courier,Monaco"> <font color=blue face="Courier New,Courier,Monaco">if <font face="Courier New,Courier,Monaco"> <font color=darkviolet face="Courier New,Courier,Monaco">bCancelInput <font face="Courier New,Courier,Monaco"> <font color=blue face="Courier New,Courier,Monaco">then <font face="Courier New,Courier,Monaco"> <font color=blue face="Courier New,Courier,Monaco">trace <font face="Courier New,Courier,Monaco"> <font color=FF0000 face="Courier New,Courier,Monaco">"Cancelled" <font face="Courier New,Courier,Monaco"> <font color=blue face="Courier New,Courier,Monaco">end <font face="Courier New,Courier,Monaco"> <font color=blue face="Courier New,Courier,Monaco">endif <font face="Courier New,Courier,Monaco"> <img src="images/triangle.gif" alt="" width="21" height="22" border="0">end - finish script The command end will simply finish the script  <font color=blue face="Courier New,Courier,Monaco">if <font face="Courier New,Courier,Monaco"> <font color=darkviolet face="Courier New,Courier,Monaco">bCancelInput <font face="Courier New,Courier,Monaco"> <font color=blue face="Courier New,Courier,Monaco">then <font face="Courier New,Courier,Monaco"> <font face="Courier New,Courier,Monaco">   <font color=blue face="Courier New,Courier,Monaco">end <font face="Courier New,Courier,Monaco"> <font color=blue face="Courier New,Courier,Monaco">endif <font face="Courier New,Courier,Monaco">  It is not necessary to put &quot;end&quot; 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. <font face="Courier New,Courier,Monaco">10 <font color=blue face="Courier New,Courier,Monaco">input <font face="Courier New,Courier,Monaco"> <font color=FF0000 face="Courier New,Courier,Monaco">&quot;Value 1 or 2&quot; <font face="Courier New,Courier,Monaco">, a <font color=blue face="Courier New,Courier,Monaco">if <font face="Courier New,Courier,Monaco"> (a==1) <font color=blue face="Courier New,Courier,Monaco">then <font face="Courier New,Courier,Monaco"> <font color=blue face="Courier New,Courier,Monaco">goto <font face="Courier New,Courier,Monaco"> 100 <font color=blue face="Courier New,Courier,Monaco">endif <font face="Courier New,Courier,Monaco"> <font color=blue face="Courier New,Courier,Monaco">if <font face="Courier New,Courier,Monaco"> (a==2) <font color=blue face="Courier New,Courier,Monaco">then <font face="Courier New,Courier,Monaco"> <font color=blue face="Courier New,Courier,Monaco">goto <font face="Courier New,Courier,Monaco"> 200 <font color=blue face="Courier New,Courier,Monaco">endif <font face="Courier New,Courier,Monaco"> <font color=blue face="Courier New,Courier,Monaco">print <font face="Courier New,Courier,Monaco"> <font color=FF0000 face="Courier New,Courier,Monaco">"I can understand 1 or 2" <font face="Courier New,Courier,Monaco"> <font color=blue face="Courier New,Courier,Monaco">goto <font face="Courier New,Courier,Monaco"> 10 <font face="Courier New,Courier,Monaco">100 <font color=blue face="Courier New,Courier,Monaco">print msg <font face="Courier New,Courier,Monaco"> <font color=FF0000 face="Courier New,Courier,Monaco">&quot;You entered One&quot; <font face="Courier New,Courier,Monaco"> <font color=blue face="Courier New,Courier,Monaco">end <font face="Courier New,Courier,Monaco"> 200 <font color=blue face="Courier New,Courier,Monaco">print msg <font face="Courier New,Courier,Monaco"> <font color=FF0000 face="Courier New,Courier,Monaco">&quot;You entered Two&quot; <font face="Courier New,Courier,Monaco"> <font color=blue face="Courier New,Courier,Monaco">end <font face="Courier New,Courier,Monaco"> 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. <font color=blue face="Courier New,Courier,Monaco">print <font face="Courier New,Courier,Monaco"> <font color=FF0000 face="Courier New,Courier,Monaco">&quot;1&quot; <font face="Courier New,Courier,Monaco"> <font color=blue face="Courier New,Courier,Monaco"> gosub <font face="Courier New,Courier,Monaco"> 100 <font color=blue face="Courier New,Courier,Monaco">print <font face="Courier New,Courier,Monaco"> <font color=FF0000 face="Courier New,Courier,Monaco">&quot;2&quot; <font face="Courier New,Courier,Monaco"> <font color=blue face="Courier New,Courier,Monaco">end <font face="Courier New,Courier,Monaco"> 100 <font color=blue face="Courier New,Courier,Monaco">print <font face="Courier New,Courier,Monaco"> <font color=FF0000 face="Courier New,Courier,Monaco">&quot;subroutine&quot; <font face="Courier New,Courier,Monaco"> <font color=blue face="Courier New,Courier,Monaco">return <font face="Courier New,Courier,Monaco"> The printed result will be: 1 subroutine 2 Note the end command before the subroutine will finish the script. It is required to have an &quot;end&quot; statement before you write any subroutines.