MobileBASIC

From Bauman National Library
This page was last modified on 1 June 2016, at 17:04.
MobileBASIC
Designed by David J Firth
First appeared 2003
Stable release
  • Phone Edition: 1.9.1 by kiriman & dzanis (the latest official - 1.92);
  • Desktop Edition: 2.3;
  • Android Edition: 3.1
  • LITE for iOS : 1.2
Filename extensions .bas, .lis
Website http://www.mobilebasic.com/
Influenced by
Basic

Mobile BASIC is a proprietary dialect of the [1] programming language that can be used to program Java-enabled mobile phones. This is possible because the interpreter is a MIDlet

Overview

In 1964, John G. Kemeny and Thomas E. Kurtz designed the original BASIC language at Dartmouth College in New Hampshire. They wanted to enable students in fields other than science and mathematics to use computers. At the time, nearly all use of computers required writing custom software, which was something only scientists and mathematicians tended to learn.

Versions of BASIC became widespread on microcomputers in the mid-1970s and 1980s. Microcomputers usually shipped with BASIC, often in the machine's firmware. Having an easy-to-learn language on these early personal computers allowed small business owners, professionals, hobbyists, and consultants to develop custom software on computers they could afford.

BASIC remains popular in many dialects and in new languages influenced by BASIC, such as Microsoft's Visual Basic. In 2006, 59% of developers for the .NET Framework used Visual Basic .NET as their only programming language

Syntax

Typical BASIC keywords

Data manipulation
  • LET: assigns a value (which may be the result of an expression to a variable.
  • DATA: holds a list of values which are assigned sequentially using the READ command.
Program flow control
  • IF ... THEN ... ELSE: used to perform comparisons or make decisions.
  • FOR ... TO ... {STEP} ... NEXT: repeat a section of code a given number of times. A variable that acts as a counter is available within the Control flow.
  • WHILE ... WEND and REPEAT ... UNTIL: repeat a section of code while the specified condition is true. The condition may be evaluated before each iteration of the loop, or after.
  • DO ... LOOP {WHILE} or {UNTIL}: repeat a section of code Forever or While/Until the specified condition is true. The condition may be evaluated before each iteration of the loop, or after.
  • GOTO: jumps to a numbered or labelled line in the program.
  • GOSUB: jumps to a numbered or labelled line, executes the code it finds there until it reaches a RETURN Command, on which it jumps back to the operator following the GOSUB - either after a colon, or on the next line. This is used to implement subroutines.
  • ON ... GOTO/GOSUB: chooses where to jump based on the specified conditions. See Switch statement for other forms.
  • DEF FN: a pair of keywords introduced in the early 1960s to define functions. The original BASIC functions were modelled on FORTRAN single-line functions. BASIC functions were one expression with variable arguments, rather than subroutines, with a syntax on the model of DEF FND(x) = x*x at the beginning of a program. Function names were originally restricted to FN+one letter.
Input and output
  • PRINT: displays a message on the screen or other output device.
  • INPUT: asks the user to enter the value of a variable. The statement may include a prompt message.
  • TAB or AT: sets the position where the next character will be shown on the screen or printed on paper.
Miscellaneous
  • REM: holds a programmer's comment or REMark; often used to give a title to the program and to help identify the purpose of a given section of code.
  • USR: transfers program control to a machine language subroutine, usually entered as an alphanumeric String or in a list of DATA statements.
  • TRON: turns on a visual, screen representation of the flow of BASIC commands by displaying the number of each command line as it is run. The TRON command, largely obsolete now, stood for, TRace ON. This meant that command line numbers were displayed as the program ran, so that the command lines could be traced. This command allowed easier debugging or correcting of command lines that caused problems in a program. Problems included a program terminating without providing a desired result, a program providing an obviously erroneous result, a program running in a non-terminating loop, or a program otherwise having a non-obvious error.
  • TROFF: turns off the display of the number of each command line as command lines run after the command TRON has been used.

Data types and variables

Minimal versions of BASIC had only integer variables and one- or two-letter variable names, which minimised requirements of limited and expensive memory (RAM). More powerful versions had floating-point arithmetic, and variables could be labelled with names six or more characters long. There were some problems and restrictions in early implementations; for example, Applesoft allowed variable names to be several characters long, but only the first two were significant, thus it was possible to inadvertently write a program with variables "LOSS" and "LOAN", which would be treated as being the same; assigning a value to "LOAN" would silently overwrite the value intended as "LOSS". Keywords could not be used in variables in many early BASICs; "SCORE" would be interpreted as "SC" OR "E", where OR was a keyword.

String variables are usually distinguished in many microcomputer dialects by having $ suffixed to their name, and values are often identified as strings by being delimited by "double quotation marks".

Arrays in BASIC could contain integers, floating point or string variables.

Some dialects of BASIC supported matrix, useful for the solution of sets of simultaneous linear algebraic equations. These dialects would directly support matrix operations such as assignment, addition, multiplication (of compatible matrix types), and evaluation of a determinant. Many microcomputer BASICs did not support this data type; matrix operations were still possible, but had to be programmed explicitly on array elements.

Standards

  • ANSI/ISO/IEC Standard for Minimal BASIC:
    • ANSI X3.60-1978 "For minimal BASIC"
    • ISO/IEC 6373:1984 "Data Processing — Programming Languages — Minimal BASIC"
  • Ecma International-55 Minimal BASIC (withdrawn, similar to ANSI X3.60-1978)
  • ANSI/ISO/IEC Standard for Full BASIC:
    • ANSI X3.113-1987 "Programming Languages Full BASIC"
    • INCITS/ISO/IEC 10279-1991 (R2005) "Information Technology - Programming Languages - Full BASIC"
  • ANSI/ISO/IEC Addendum Defining Modules:
    • ANSI X3.113 Interpretations-1992 "BASIC Technical Information Bulletin # 1 Interpretations of ANSI 03.113-1987"
    • ISO/IEC 10279:1991/ Amd 1:1994 "Modules and Single Character Input Enhancement"
  • Ecma International-116 BASIC (withdrawn, similar to ANSI X3.113-1987)

BASIC evolution

Unstructured BASIC

The original Dartmouth Basic was unusual in having a matrix keyword, MAT Although dropped by most later microprocessor derivatives it is used in this example from the 1968 manual which averages the numbers that are input:

5 LET S = 0 
10 MAT INPUT V 
20 LET N = NUM 
30 IF N = 0 THEN 99 
40 FOR I = 1 TO N 
45 LET S = S + V(I) 
50 NEXT I 
60 PRINT S/N 
70 GO TO 5 
99 END

New BASIC programmers on a home computer might start with a simple program, perhaps using the language's PRINT statement to display a message on the screen; a well-known and often-replicated example is Hello world program:

10 PRINT "Hello, World!"
140 END

An infinite loop could be used to fill the display with the message.

Most first-generation BASIC versions such as MSX BASIC and GW-BASIC supported simple data types, loop cycles and arrays. The following example is written for GW-BASIC, but will work in most versions of BASIC with minimal changes:

10 INPUT "What is your name: ", U$
20 PRINT "Hello "; U$
30 INPUT "How many stars do you want: ", N
40 S$ = ""
50 FOR I = 1 TO N
60 S$ = S$ + "*"
70 NEXT I
80 PRINT S$
90 INPUT "Do you want more stars? ", A$
100 IF LEN(A$) = 0 THEN GOTO 90
110 A$ = LEFT$(A$, 1)
120 IF A$ = "Y" OR A$ = "y" THEN GOTO 30
130 PRINT "Goodbye "; U$
140 END

The resulting dialog might resemble:

What is your name: Mike
Hello Mike
How many stars do you want: 7
*******
Do you want more stars? yes
How many stars do you want: 3
***
Do you want more stars? no
Goodbye Mike

Structured BASIC

Second-generation BASICs introduced a number of features into the language, primarily related to structured and procedure-oriented programming. Usually, line numbering is omitted from the language and replaced with labels (for GOTO) and procedures to encourage easier and more flexible design. In addition keywords and structures to support repetition, selection and procedures with local variables were introduced.

The following example is in QuickBASIC:

DECLARE SUB PrintSomeStars (StarCount!)
REM QuickBASIC example
INPUT "What is your name: ", UserName$
PRINT "Hello "; UserName$
DO
   INPUT "How many stars do you want: ", NumStars
   CALL PrintSomeStars(NumStars)
   DO
      INPUT "Do you want more stars? ", Answer$
   LOOP UNTIL Answer$ <> ""
   Answer$ = LEFT$(Answer$, 1)
LOOP WHILE UCASE$(Answer$) = "Y"
PRINT "Goodbye "; UserName$
END

SUB PrintSomeStars (StarCount)
   REM This procedure uses a local variable called Stars$
   Stars$ = STRING$(StarCount, "*")
   PRINT Stars$
END SUB

Description of Mobile BASIC

Mobile BASIC is an end user BASIC Interpreter that runs directly on your Android Device. Mobile BASIC is the ideal tool for rapidly creating your own programs that you need to support your professional, work or educational life. Mobile BASIC is supplied with a extensive list of example programs illustrating all aspects of this powerful mobile programming environment.

Mobile BASIC is a structured version of BASIC which can be learnt with the minimum amount of time and effort yet still supports many powerful features including Subroutines, Functions, Ten Data Types, Single and Multi-Dimensional Arrays, String Handling, Maths Functions, File Input and Output, Time and Date Handling, Graphics Facilities and support for Android Sensors.

Arithmetic operations

Mobile BASIC provides a variety of operators including arithmetic, relational and logical and bitwise. The arithmetic operators include

+ add
- subtract/minus
* multiply
/ divide
 % mod (The modulus operation returns the remainder after a division)
** power
(-) unary minus

together with an unlimited number of parenthesis.

Comparisons

The relational operators are used to make comparisons between values and enable you to check for

= equality
<> inequality
< less than
<= less than or equal to
> greater than
>= greater than or equal to

Logical operations

The logical operators include

  • AND
  • OR
  • NOT

and these allow you to build more complex relational expressions by linking combining several relational expressions into a single logical expression.

If your programs are dealing with integer values:

  • BYTE
  • SHORT
  • INTEGER
  • LONG

then there are several additional bitwise operators including

Bitwise operations

& AND
| OR
^ XOR
~ bit complement
<< left shift
>> right shift
>>> unsigned right shift

Main Features

  • Structured dialect of BASIC with
    • Subroutines
    • Functions
    • Arrays
    • etc.
    Ten data types including
    • BOOLEAN
    • BYTE
    • SHORT
    • INTEGER
    • LONG
    • FLOAT
    • DOUBLE
    • COMPLEX
    • STRING
    • VARIANT.
  • Built in functions for
    • String Handling
    • Time and Date
    • Trigonometry (Cosine, Sine, Tangents, Cosecants, Secants and Cotangents)
    • Hyperbolic Functions
    • Logarithms
  • Graphics Facilities including
    • SETCOLOR
    • SETFONT
    • PLOT
    • DRAWLINE
    • DRAWARC
    • DRAWCIRCLE
    • DRAWOVAL
    • DRAWPIE
    • DRAWRECT
    • DRAWROUNDRECT
    • DRAWSTRING
    • FILLARC
    • FILLCIRCLE
    • FILLOVAL
    • FILLPIE
    • , FILLRECT
    • FILLROUNDRECT
    • SAVE
    • RESTORE
    • TRANSLATE
    • ROTATE.
  • Support for Android sensors incuding
    • Touch Screen
    • Location Services
    • Accelerometer Sensor
    • Ambient Temperature Sensor
    • Gravity Sensor
    • Gyroscope Sensor
    • Light Sensor,
    • Linear Acceleration Sensor
    • Magnetic Field Sensor
    • Pressure Sensor
    • Proximity Sensor
    • Relative Humidity Sensor
    • Rotation Vector Sensor
    • Temperature Sensor.

MobileBASIC for Desktop

The main IDE for Mobile BASIC is the desktop version of this interpreter. The source code in Desktop version is slightly different than mobile version analogues, more like a Quick Basic dialect.

The main feature is a heavy modularisation, with the main procedure called Main (Sub Main()). Though this is still an interpreted language, which is more effective than previous versions.

This version includes a built-in maps support, which allows you create and modify different maps and tiles (Editors included). This version is built specifically for game development, while it has a graphic element (sprite) support.

The IDE includes code highlighting and editor and some additional editors: Tile Editor, Map Editor, Image Resize, Color Chooser and a built-in emulator. The IDE is written in Java SE, which allows users to run it on any Java VM compatible machine.

Mobile BASIC for Desktop example

The last stable version is 2.3 [2].

MobileBASIC for Android

The world met a new Development Environment for Mobile BASIC in June 2011. THis time it was an IDE for Android. The Syntax looks a lot like the desktop version BASIC, but from now on multi-dimensional arrays, user procedures and functions are available.

The programme includes a responsive help for language and around 100 examples of language usage. There are 2 IDE versions: free (with ads) and for £2.99 without

The last stable release is 4.9.11.

Mobile BASIC for Android example

MobileBASIC LITE for iOS

In 2012 Mobile BASIC influenced another mobile platform, this time - iOS. The newest version is called MobileBASIC LITE. There are a lot of different functions included, specific for iOS-based devices.

These are:

  • specific location mechanism
  • accelerometer introduction
  • hyroscope introduction
  • built-in maps integration
  • databases
Mobile BASIC for iOS example

As in the previous versions, the IDE includes a wealthy knowledge base about basic language structures

References:

  1. BASIC
  2. MobileBASIC Desktop Edition Homepage

External links

  1. MobileBASIC