AmigoBasic for Android
Version 1
Jordi Sorroche Pérez
jsptron@gmail.com
Barcelona in June 2012
What is AmigoBasic?
It is a programming language for high level (close to natural language)
especially designed for mobile platforms, further PM-as tablets and
smartphones.
It is inspired by the original Basic language (Beginners All-purpose Symbolic
Instruction Code), 1964, although as we shall see below, with significant
differences, especially in the edition of the program.
Who is it for?
It is intended for all those people who want to learn to program and / or also to
those already initiated in the matter, who want to solve a problem in any place
and at any moment by the flexibility and convenience we provide the PM. And
of course, for enthusiasts to programming.
Key features of AmigoBasic; Modules:
In most programming languages, if not all, as the Basic, enter the instructions
for creating a program, we make them freely by an editor. Unfortunately, this is
painfully slow and tedious when we do from a mobile or tablet, as most of them
have no physical keyboard and / or too small at their keyboards and screens. In
addition, we must add the inconveniences which publishers when entering the
instructions and that the PM can be accentuated even more:
- We must remember the syntax of the instructions.
- We have to write it in the form and proper order.
- We do not know in advance the parameters of the same.
- High probability of committing syntax error misspelled.
- High probability of making incorrect parameter error.
Given this, AmigoBasic had to have an intuitive editor, easy and fast, and the
overall operation of the program.
To overcome these drawbacks, the introduction of instructions performed by the
modules AmigoBasic. Modules are forms in which the values that make a
particular statement is parameterized to form an expression (combination of
operands, operators, and data-operations to be performed-). In other words, a
module is the sheet with a statement that contains all the necessary data to be
processed correctly. In fact, the lines that make up a program modules are in
reality.
There are three types of modules: Input, Process and Output:
Input:
Data entry, example: from the keyboard, buttons, etc ...
Process:
Data processing, example: math, conditions, etc ...
Output:
Data output, example: on screen, sound, etc ...
Thoroughly explained later operation of each module.
Operation and programming environment AmigoBasic:
Wen running the screen will appear AmigoBasic editor-blue background and
the legend of 'Ready!' - Indicating that we can begin programming.
Pressing the Menu button, will show us the General Menu the following
options:
Input Modules:
Are represented in a list all the input modules.
Process Modules:
In this option, displays the process modules.
Output Modules:
Here we will output modules.
Run Program:
We click on this option to run the program.
Edit Program:
You can select four options:
Program List:
With this option we can list the current program.
Delete Program:
To delete the program we have loaded in memory PM.
Delete Module:
Deletes a specific module of the program (prompts you to enter the line number
to delete).
Insert Module:
This option allows us to insert a module between two lines, example if we want
to insert a module between lines one and two, simply enter the number two.
More:
Here are seven options:
Load Program:
Loads a program from the SD card installed in our PM to the memory of the
device.
You can also import a program from the email (for example).
To do this, open the e-mail in particular, save the attachment (the program) and
store it in the location (/ / SD), plain and simple.
Save Program:
With this option will save the program we found created in the SD of our PM.
We can also export the program that we created by an email, for example.
To do this, we go to the-file option in her menu Android-(in the location / / SD)
and at the end of the list are all of our programs saved. We choose what
interests us, and give the 'share-send mail Elec ..', as an attachment, that simple.
Save Program_List:
It allows us to save the program readable format any text editor (on a PC or
even in PM), to be able to print if you so desire. Because, if we view a program
previously saved with 'Save Program', would not understand anything, because
the program consists of codes that can only interpret AmigoBasic.
Save Screen:
Save the image created by the last execution of the program (not visible
buttons).
Time Change Process:
It gives us the possibility to change the processing time in the execution of a
program, in milliseconds between modules. By default, is configured with a
value of 100, being able to change this value to at least 1 and up to 2000 (2
seconds). It is important to note that you should not abuse really short time,
since our device has to process other tasks other than ours, and this may lead to
malfunction of the program. Without overheating and excessive consumption of
the battery. It is advisable not to drop below 10 milliseconds.
Help (English/Spanish):
Tutorial program performance in English / Spanish.
About AmigoBasic:
About creating AmigoBasic.
Beginning programming with AmigoBasic:
First, briefly explain the basics of programming, for those initiated into the
matter.
What is a program?
A program is an ordered set of instructions that the computer will 'read' one
after another vertically-from top to bottom. Most programs, if not all, are
composed of input, memory, process and output data. For example, a program
introduced by multiply the number 9 would be something like:
Input to
b = a * 9
Print b
The first line would be a data input, then asks you to enter a number that is
assigned to variable 'a'.
The second line is the process, it multiplies the value of the variable 'a' by 9 and
assigned to variable 'b'.
And the third line would output data, as we print the value of 'b'.
The variables used would be the memory. This simple, is the basis of any
program.
What you need to be clear before you start coding, it's like to face a particular
problem and structure as possible. That is, by analogy, to build a house, start up
the walls and the roof.
Important:
Fields marked with '*' are required.
Assignment variables are automatically converted to lowercase.
The constants PI and E are all uppercase.
String constants are enclosed in single quotes, example: 'name'
Both variables as the matrix are of the generic type, or may contain numbers or
strings. Ex: a = 5 or a = 'hello'.
You must initialize the variables.
In our programs, we can use an array of two dimensions, always call: matrix1,
a, b, where 'a' index and 'b' the subscript of the table.
The maximum value for the array index is 999 for 5 of subscripts.
It is not necessary to initialize the values of the matrix.
Our first program written in AmigoBasic:
Let's make a simple program which we call 'Hello_World'.
In the editor, press 'Menu', select the option Output Modules, and it will press
Screen / Print. We will open the module relative to Print (Print Screen). Fill the
box 'Text' with the phrase 'hello_world', immediately afterwards press the 'OK'
button. Will appear in the editor our first line of program. If you look, a little
above, tells us what position the next line inserted. Now let's run it. This will
press the key again 'Menu' then 'Run Program'.
We see that the phrase appears on the screen that we introduced earlier: 'Hello
World _'. Also displays a button labeled 'Esc' at the top left, with him we can
interrupt the execution of the program at any time, provided we are not in the
input (Input Module). Logically, this button only appears when the program is
running.
Detailed information about the modules:
Here we will explain the characteristics of each module: type location,
configuration, and the functions it performs:
Input Modules:
Input
Type: Data input from the keyboard.
Location: Menu / Input Modules / Keyboard / Input
1 º field: * Variable allocation
2 nd field: Text
3 rd field: Variable: Numeric value / string
Function: Responsible for collecting the data entered from the keyboard to
assign to the variable of 1 field. Also shown are optionally display the text of
the 2nd field and / or value of the variable on the 3 rd field and waits for you to
press a button.
Message
Type: Input data from button
Location: Menu / Input Modules / Button / Message
1 º field: Text
2 nd field: Variable: Numeric value / string
Function: Displays text from 1 field and the value of the variable from 2 ° field
and waits for you to press a button.
Buttons On
Type: Input data from button
Location: Menu / Input Modules / Buttons On
Direct input.
Function: Display can display four buttons control which button was pressed by
the system variable but.
These are the values returned by the variable but when one of the four buttons:
Button1 = 1, boton2 = 2, 3 and boton3 = Button4 = 4. To initialize but, we use
the value 0: but = 0.
Buttons Off
Type: Input data from button
Location: Menu / Input Modules / Off Buttons
Direct input.
Function: They disappear from the screen the four buttons.
Process Modules:
Rem
Type: Process / Rem
Location: Menu / Process Modules / Rem
1 º field: * Text
Operation: there is no process is simply a text that will help us discuss the
different lines of our program.
Stop
Type: Process / Stop
Location: Menu / Process Modules / Stop
Direct input.
Function: Stops the program execution.
Pause
Type: Process / Pause
Location: Menu / Process Modules / Pause
1 º field: * Constant: Numeric value
Function: Stops the program execution for the specified time on 1 field in
milliseconds.
Let
Type: Process / Assignment
Location: Menu / Process Modules / Let
1 º field: * Variable allocation
2 nd field: * Variable / Constant: Numeric value / string
Function: Assigns the value of 2 ° field with the variable of 1 field.
Math / Operators
Type: Process / Math / Operators
Location: Menu / Process Modules / Math / Operators
1 º field: * Variable allocation
2 nd field: * Variable / Constant: Numeric value
3 rd field: * Variable / Constant: Numeric value
4 th field: * Self-expression
Function: We select an operator to perform the calculation between 2 º and 3 º
field. Clicking the Insert button, the previous result is added to the 4 th field,
adding more stones at a time if you like. The value of the 4 th field is assigned
to the variable of 1 field.
Operators: +, -, *, /, ^
The order of processing for calculation is from left to right.
Parentheses are not allowed.
Math / Functions
Type: Process / Math / Functions
Location: Menu / Process Modules / Math / Functions
1 º field: * Variable allocation
2 nd field: * Variable: A numeric value
Function: We select a function to perform for the variable value of the 2 nd half.
The return value is assigned the variable to 1 field.
Features:
Sqr: is the square root.
Int: returns the integer
Abs: turns a negative into a positive value.
Log: gives the logarithm to base 10.
Exp: raises the number mathematician E.
Sin: returns the sine.
Cos: gives the cosine.
Tan: returns the tangent.
Atn: gives the arc tangent.
Rnd
Type: Process / Math / Random
Location: Menu / Process Modules / Math / Rnd
1 º field: * Variable allocation
2 nd field: * Variable / Constant: Numeric value
3 rd field: * Variable / Constant: Numeric value
Function: sets the variable to 1 field a random number between the ranges of 2
and 3 field.
With the option Integer, you can specify whether or not we want to decimal.
If ... Then
Type: Process / Conditional
Location: Menu / Process Modules / Condition / If ... Then
1 º field: * Variable: Numeric value / string
2 nd field: * Variable / Constant: Numeric value / string
3 rd field: * Self-expression
Function: We select a relational operator to determine the values of 1 and 2
field. Also, optionally, will choose the logical operator to build the condition.
Clicking the Insert button, the above condition is added to 3 ° field, adding more
conditions at once if you like.
Relational operator: =, <>, <,>, <=,> =
Logical operator: And, Or, Xor, Not
The order of process conditions is from left to right.
Parentheses are not allowed.
Else
Type: Process / Conditional
Location: Menu / Process Modules / Condition / Else
Direct input.
Function: If the condition preceded by If ... Then is not met, the modules are
processed just under Else.
End If
Type: Process / Conditional
Location: Menu / Process Modules / Condition / End If
Direct input.
Function: ends the conditional If...Then / Else.
For
Type: Process / Loop
Location: Menu / Process Modules / Loop / For
1 º field: * Variable allocation
2 nd field: * Variable / Constant: Numeric value
3 rd field: * Variable / Constant: Numeric value
4 th field: * Variable / Constant: Numeric value
Function: performs a For ... Next loop, since the value of 2 ° to 3 ° field value
with increases in the value of the 4 th field, and finally assign it to the variable of
1 field.
Next
Type: Process / Loop
Location: Menu / Process Modules / Loop / Next
Direct input.
Function: close the loop For ... Next.
Exit For
Type: Process / Loop
Location: Menu / Process Modules / Loop / Exit For
Direct input.
Function: exit the For ... Next loop.
Do
Type: Process / Loop
Location: Menu / Process Modules / Loop / Do
Direct input.
Function: Starts the Do ... Loop Until loop.
Until Loop
Type: Process / Loop
Location: Menu / Process Modules / Loop / Loop Until
1 º field: * Variable: Numeric value / string
2 nd field: * Variable / Constant: Numeric value / string
3 rd field: * Self-expression
Function: using a combo you can select the relational operator to determine the
values of 1 and 2 field. Also, optionally, in a 2nd combo, will choose the logical
operator to build the condition. Clicking the Insert button, the above condition
is added to 3 ° field, adding more conditions at once if you like.
Relational operator: =, <>, <,>, <=,> =
Logical Operator: And, Or, Xor, Not
The order of process conditions is from left to right.
Parentheses are not allowed.
Exit Do
Type: Process / Loop
Location: Menu / Process Modules / Loop / Exit Do
Direct input.
Function: Loop Until loop exits.
Mid
Type: Process / String
Location: Menu / Process Modules / String / Mid
1 º field: * Variable allocation
2 nd field: * Variable / Constant: Value String
3 rd field: * Variable / Constant: Numeric value
4 th field: * Variable / Constant: Numeric value
Function: Select the string value of field 2 ° the characters from the value of 3 °
to 4 ° field value to assign to the variable of 1 field.
String / Functions
Type: Process / String
Location: Menu / Process Modules / String / Functions
1 º field: * Variable allocation
2 nd field: * Variable / Constant: Numeric value / string
Function: We select the function to perform for the value of 2 ° field. The
return value is assigned the variable to 1 field.
Features:
Length: Returns the character length
Chr: gives a character code value corresponding to the numeric ASCII
(American Standard Code for Information Interchange).
Asc: returns a number corresponding to the ASCII character code
Concatenate
Type: Process / String
Location: Menu / Process Modules / String / Concatenate
1 º field: * Variable allocation
2 nd field: * Variable / Constant: Value String
3 rd field: * Variable / Constant: Value String
4 th field: * Self-expression
Function: we concatenate the field values 2 º and 3 º pressing the Insert button.
The union of the strings are added to the 4 th field, adding more linkages at a
time if you like. The value of the 4 th field is assigned to the variable of 1 field.
The process order for the concatenations is from left to right.
Parentheses are not allowed.
Sub
Type: Process / Subroutine
Location: Menu / Process Modules / Subrutine / Sub
1 º field: * Text
Function: subroutine names the Sub ... End Sub.
End Sub
Type: Process / Subroutine
Location: Menu / Process Modules / Subrutine / End Sub
Direct input.
Function: Ends the subroutine Sub ... End Sub.
Call
Type: Process / Subroutine
Location: Menu / Process Modules / Subrutine / Call
1 º field: * Text
Function: call the subroutine with the name of 1 field.
Exit Sub
Type: Process / Subroutine
Location: Menu / Process Modules / Subrutine / Exit Sub
Direct input.
Function: exit the subroutine Sub ... End Sub.
Point
Type: Process / Display
Location: Menu / Process Modules / Screen / Point
1 º field: * Variable allocation
2 nd field: * Variable / Constant: Numeric value
3 rd field: * Variable / Constant: Numeric value
Function: Checks if a character printed on the screen in the X (value of 2 ° field)
and Y (value of 3 ° field). If yes, assign the variable to 1 field the value of True.
The opposite is False.
Output Modules:
Print
Type: Output / Display
Location: Menu / Output Modules / Screen / Print
1 º field: Text
2 nd field: Variable: Numeric value / string
3 rd field: Variable / Constant: Numeric value
4 th field: Variable / Constant: Numeric value
Function: prints out the text from 1 field with the value of the 2nd field in the X
(3 ° field) and Y (4 ° field)-optional.
Cls
Type: Output / Display
Location: Menu / Output Modules / Screen / Cls
Direct input.
Function: Clears the screen.
Color Paper
Type: Output / Display
Location: Menu / Output Modules / Screen / Color Paper
1 º field: Variable / Constant: Numeric value
Function: Defines the background color for the value of 1 field to the following
code:
0 = black 1 = dark gray 2 = medium gray 3 = light gray
4 = red 5 = green 6 = blue 7 = yellow
8 = magenta 9 = cyan 10 = white
Color Ink
Type: Output / Display
Location: Menu / Output Modules / Screen / Color Ink
1 º field: Variable / Constant: Numeric value
Function: Set the text color for the value of 1 field to the following code:
0 = black 1 = dark gray 2 = medium gray 3 = light gray
4 = red 5 = green 6 = blue 7 = yellow
8 = magenta 9 = cyan 10 = white
Beep
Type: Output / Sound
Location: Menu / Output Modules / Sound / Beep
Direct input.
Function: generates a sound of short duration.
List of errors
No. 1: No program in memory.
No. 2: The variable x is not initialized.
No. 3: If ... Then without Else or End If.
No. 4: Else without End If.
No. 5: You can only determine between numbers.
No. 6: Loop without Do.
No. 7: For without Next.
No. 8: Next without For.
No. 9: The Subroutine x does not exist.
No. 10: End Sub without Call.
No. 11: You have exceeded the maximum allowed nested subroutines (99).
No. 12: Exit For without Next.
No. 13: Exit Do without Loop Until.
No. 14: Exit Sub without Call.
No. 15: Error processing overhead.
No. 16: You have exceeded the maximum allowed of variables (99).
No. 17: You have reached the maximum permitted modules (199).