Sie sind auf Seite 1von 14

Tap

BASIC Manual
Navigation

Layout
TapBasics main screen has the following layout: menu (top right hand corner); screen toggle to change the layout of the program and run screens; program (white) and run (blue) screens; and keypad. The keypad has special keys for running a program, debugging a program, displaying the graph screen, saving a file, stopping a running program and performing other file operations such as load file, upload to Dropbox, email etc. There are also drop down lists for quickly inserting commands or expressions the Expr and Cmd keys. The canvass button (with the art canvass icon) displays the graph screen. Touch and graph the graph screen to move it wherever you want it on the main screen. Double tap on the graph screen to hide it.

Menu
The menu items: Item Show Memory Decimal Places TapBasic Manual About Cancel

Description Navigate to a screen showing the variable names currently in memory and their values . Values can be displayed in decimal, hexadecimal or scientific notation Select the number of decimal places to be displayed in results of calculations Displays this manual for quick reference Display information about TapBasic eg version number Go back to the main screen

Screen Toggle
Item Prog RunScrn Split Description Show only the program screen with the keypad Show only the run screen with the keypad Show both the program and run screens in a split view

ProgFull RunFull

with the keypad The program screen takes up the whole main screen. The keypad is hidden and the iPhones soft keyboard is used for editing The program screen takes up the whole main screen. The keypad is hidden

Entering and Running a Program

You enter a program by pressing keys on the keypad or tapping the program screen and using the iPhones soft keyboard. You should ensure that the program screen is visible using the screen toggle when you are entering a program. You run a program by pressing Run. You dont press = to run a program. The = is used for assigning values to variables and for boolean expressions. TapBasic adds quick references buttons to the top of the iPhones soft keyboard. Pressing a quick reference button displays a dropdown list in the top right corner of the screen. Scroll through and tap an item in the dropdown list for quick entry of commands, expressions or operators.

Debugging a Program

A program can be debugged by pressing the Debug button instead of the Run button. When you press Debug the text in the program screen turns red and an arrow indicates which line of the program is about to be executed. Execution of the program will pause until you press the Run key. When you press the Run key, the program will continue until the next command. The program pauses and you press Run again to execute to the next command, and so on Whilst in debug mode you can press the Menu button and navigate to the Show Variables screen to observe the variables in memory and their values. To stop debugging in the middle of the executing the program press the Stop key (the key with the stop sign icon).

Files and Dropbox Integration

The file screen enables files to be loaded, run without loading (using the green run button), uploaded to Dropbox (if you link to a Dropbox account) emailed, or deleted. When you link to Dropbox a new folder called TapBasic is created in your Dropbox folder. All files uploaded to Dropbox by TapBasic are saved in the TapBasic folder.

Variables
Variable Types
All variables in Tap BASIC are decimal, hex or exponent numbers. They are either standard variables or arrays (also known as tables). Type Specifications Examples Standard Combination of letters and A, a, myVar, xyz123 numbers up to 8 chars long. (A is the same as a) Must start with a letter. Case is ignored. Array/Table Naming as above but is A(10), abc1(15), followed by (x) or (x,y). (x) is a board(10,6),grades(abc,10) one dimensional array and (x,y) is a two dimensional array. x and y each have a maximum of 100. Variable names cannot be names of commands or expressions (see Commands and Expressions below).

Standard Variables
Standard variables can be assigned values with the = sign. The keywords let and mem are optional. The following are examples: Examples let a=50 mem a=50 a=50 cash=60.57 Ahex=0x12 myexpnt=1e10 Hex numbers must begin with 0x.

Arrays
Arrays must be defined with the dim or table commands before they can be used. If not, there will be a Table not defined error. Examples dim mytab(50) dim atable(5,8) table myclass(100)

dim gamboard(20,20) Once an array has been declared, it can then be used like a standard variable for each element. Examples dim mytab(8) mytab(1)=5 dim atable(5,5) let atable(1,2)=5

Displaying Variables
A program can display the value of a variable on the screen either by using the name of the variable or with the print or text command. Example Result a=5 5 a xyz=0xc the hex value of 0xc in decimal is 12 print the hex value of 0xc in decimal is +xyz input input any number,anynum your number is <whatever was entered text your number is ,anynum in the dialog box>

Calculations

Calculations are entered as in any calculator. They are executed when the Run key is pressed. The order of precedence is as follows: Operator Precedence Brackets First ! and ^ and % Second * and / Third + and - Fourth Note: the format for a number to the power of a negative number is: x^(-y) ie brackets are mandatory x^-y will cause a syntax error Examples:

Expression 4-2*3 (4-2)*3

Result -2 6

Boolean Expressions

Boolean expressions evaluate to either true or false and are used in commands such as if, while and cond. In Tap Basic, these following symbols are used in boolean expressions: Operator Meaning & and @ or > greater than < less than = equal to >= greater than or equal to <= less than or equal to <> not equal to Examples if a<8 & a>5 while myvar<>5 if (xy>z @ xy>=cb) & xy<>17

Commands
General
Tap BASIC has the commands listed below. Commands are not case sensitive, so ASK is the same as ask, Ask or aSk.

input/ask

Description Displays a message in a dialog box. The dialog box has a field for entering a number or expression. Pressing ok dismisses the dialog box

Syntax input text,VAR OR ask text,VAR Key text is any text or number

Examples input enter a number,mynum ask What is your age?,age

VAR is the name of a standard variable or array

call
Description Runs a program saved in the Tap BASICs documents folder without loading the file into the program screen. Call can be used to run separate modules of a program during runtime (ie when a program is already running). Syntax call <filename> Key <filename> is the name of a file already saved in Tap BASICs documents folder Examples call program2 if zg2=5 call executezg endif

clrmem
Description Syntax Clears all variable names and clrmem values from memory. Until this command is used, variable names and their values will be retained, even if a program is re-run. Examples x=1 x (output :1) clrmem x (output: Unknown variable: x)

cls/clrscrn
Description Clears the run screen Syntax cls clrscrn

condition

Description Specifies that the next x commands will only be executed if a condition is satisfied

Syntax cond NUM <boolean> <commands> Key

Examples i=1 cond 1,i=2 print This line wont execute

NUM is any integer or variable and specifies the number of commands to be executed if the condition is satisfied <boolean> is a boolean expression

print This line will execute and this text will be displayed cond 2,i>5 print This line wont execute print This line wont either print This line will execute

rem/ct
Description Places a comment in the program. The comment ends with a *. The comment is ignored at runtime. Syntax rem TEXT * ct TEXT * Key TEXT is any letter, number or symbol other than a * Examples rem this line will be ignored* ct this is a comment 1234 *

dim/table
Description Initialises an array of variables. If an array is used without declaring it first, an error will result Table not declared Syntax dim VAR(x) dim VAR(x,y) table VAR(x) table VAR(y) Key VAR is the name of a standard variable or array x and y are numbers or the name of a variable Examples dim myarray(6) myarray(1)=5 myarray(2)=10 xyz=myarray(1)

for/next
Description Loops through a range of numbers until the first number in the range is equal to the last number in the range Syntax for VAR=NUM to NUM for VAR=NUM to NUM step +/- NUM Key Examples call program2 if zg2=5 call executezg endif

The first number can ascend or descend towards the second number by one or by a greater or lesser number using step

VAR is the name of a standard variable or array NUM is a variable, number or numerical expression +/- is + or -

graph/line
Description Draws a line on the graph screen from one point to another in a specified color Syntax graph x1,y1,x2,y2,color line x1,y1,x2,y2,<color Key x1 is the x value of the starting point y1 is the y value of the starting point x2 is the x value of the endpoint y2 is the y value of the endpoint Each of x1, y1, x2, and y2 is a variable, number or numerical expression between 0 and 200 (the graph screen is 200x200 pixels) Color is a symbol that equates to any one of the colors specified below Examples graph 0,100,100,100,r for i=1 to 100 line i+10,1,i,20,g next

The choice of colors is as follows: Symbol Color w white r red y yellow g green b blue k black c cyan e grey o orange p purple d delete line ie restore to original graphic screen color

if/endif

Description Sets a condition for the execution of commands. If the condition is not satisfied then the commands between the if and endif are not executed

Syntax if <condition> <commands> endif Key <condition> is a boolean expression <commands> is one or more commands

Examples if xyz<>20 print not twenty endif

keyreset
Description The key function reads a number from the keypad. It will keep the value of the last key pressed until keyreset is called Syntax keyreset Examples j=key if j=2 print 2 endif keyreset

let/mem

Description Assigns a value to a a standard variable or an element in an array

Note: let and mem are optional for assigning values. They do not need to be used.

Syntax let x=NUM mem x= NUM Key NUM is a variable, number or numerical expression

Examples let j=5 mem myscore=points*100

print/text
Description Syntax Examples

Displays text on the run screen

print <text> text <text> print <text>+TVAR+TVAR+ text <text>+TVAR+TVAR+ Key <text> is one or more letters, numbers or symbols TVAR is <text> or the name of a standard variable or array

let j=5 print J is equal to +j text Hello Tap BASIC hour=chour minute=cminute second=csecond print The time is +hour+:+minute+:+second

repeat

Description Repeats the next x commands if a condition is satisfied

Syntax repeat NUM <boolean> <commands> Key NUM is any integer or variable and specifies the number of commands to be executed if the condition is satisfied <boolean> is a boolean expression

Examples i=1 repeat 2,i<4 print This line will repeat 3 times i=i+1 print This line will not repeat Note: repeat 2 is used so that the line i=i+1 also repeats. If repeat 1 is used then there is an endless loop because the value of i remains unchanged

solve

Description Solves a linear equation for x

Syntax Solve NUM[x] + NUM=NUM Solve NUM[x] - NUM=NUM Key

Examples solve 2[x]+1=9 solve pi*a[x]+sin(5)=6!

NUM is a variable, number or numerical expression

while/wend

Description Loops through commands between whileand wend until the specified condition is satisfied

Syntax while<condition> <commands> wend Key <condition> is a boolean expression <commands> is one or more commands

Examples i=1 while i<10 print i: +i wend

Format commands
Format commands specify the format in which numbers are to be displayed in the run screen until another format command is encountered. Description Syntax Examples Specify the format of FDEC i=10 numbers to be displayed FHEX FHEX from that point in the FEXP print hex: +i program onwards until FEXP another format command is print exponent: +i encountered. FDEC Decimal: FDEC Hexadecimal: FHEX Scientific notation: FEXP When a program is run the default is set to FDEC

Functions

Use functions in setting the values of variables or making calculations. The following functions are used in the Tap Basic:
Expression rnd(x) int(x) key Description

returns a random number between 0 and x returns the integer of x reads a number from the keypad without pausing log(x) returns the value of the logarithm of x to base 10 sin(x) returns the sine of x in radians cos(x) returns the cosine of x in radians tan(x) returns the tangent of x in radians sqrt(x) returns the square root of x sqr(x) returns the square of x ln(x) returns the natural logarithm of x pi returns p asin(x) returns the arc sine of x in the range -1 to 1 acos(x) returns the arc cosine of x in the range 0 to p atan(x) returns the arc tangent of x in the range p/2 to p/2 sinh(x) returns the hyperbolic sine of x cosh(x) returns the hyperbolic cosine of x tanh(x) returns the hyperbolic tangent of x aabs(x) returns the absolute value of x exp(x) returns the base-e exponential of x ndst(x) same as Excel NORMSDIST ndinv(x) same as Excel NORMSINV stddev e x1,x2,x3... returns the population standard deviation of the numbers x1,x2 etc up to e numbers. Max value of e is 100 stddevs returns the sample standard deviation of the numbers x1,x2 etc up to e numbers. Max value of e is 100 cday returns the current day cmonth returns the current month cyear returns the current year chour returns the current hours cminute returns the current minute csecond returns the current second *x, x1, x2 etc and e are numerical expressions so can be numbers, variables or computations of numbers and variables

Error messages
Error message Divide by zero Unknown command Description The numerical expression is attempting to divide a number by zero There is a syntax error

Decimal point error Number expected Name expected Name too long Memory Full Unknown variable Invalid equation Call: File not Found Table limit exceeded Table not declared Duplicate memory name Table: Length not declared Missing: x Table has too many elements Too many elements for standard deviation No color specified Endif without if Wend without while Wrong use of 'Ask' For without next Next without for

There is more than one decimal point or the syntax of a numerical expression is incorrect The interpreter expects there to be a number but there is some other text, number or symbol The interpreter expects there to be a variable name but there is some other text, number or symbol The variable name exceeds 8 characters The maximum number of variables has been reached. The maximum is 100 The variable name is not recognized because the variable has not been assigned any value The syntax for the solve command is incorrect The call command has attempted to load a file that is not saved in the documents folder The maximum number of arrays that can be declared has been reached. The maximum number of arrays is 100. There is a reference to an array variable that has not previously been declared with the dim or table command The same variable name is being initialized more than one The syntax for dim or table is incorrect The interpreter is expecting a missing character or symbol x An array has been declared with too many members. Maximum number of members is 100 The maximum number of elements for the standard deviation function of 100 has been exceeded The syntax of the graph or line command is incorrect An endif command is used without a corresponding if command A wend command is used without a corresponding while command The syntax for the ask or input command is incorrect A for command is used without a corresponding next command A next command is used without a corresponding for command

Example programs

Unit conversion (contributed by Franklin Bretschneider)


rem unit conversion* input "enter temp in Celcius ",c f = c*9/5+32 print "is in Fahrenheit "+f

Quadratic equation (contributed by Franklin Bretschneider)


rem root formula (quadratic equation)* input " ax^2 + bx +c = 0 input a ", a input "input b",b input "input c",c d = b^2-4*a*c if d<0 print " no real roots" endif if d=0 x=(-b/2/a) print "one root "+x endif if d>0 x1=(-b+sqrt(d))/2/a x2=(-b-sqrt(d))/2/a print "two roots "+x1 print "and "+x2 endif

Das könnte Ihnen auch gefallen