Fundamentals of BASIC

From NSB App Studio
Revision as of 10:11, 10 December 2013 by Ghenne (talk | contribs)
Jump to navigation Jump to search

Variables

Naming

The following list shows some variable names that are allowed by AppStudio:

text
LLAMAS
Jupiter
W1Spec
SouthPark

And some that are not allowed:

1table          'starts with a number 
X&Ycords        'uses special character & 
first counter   'has a space 
%correct        'does not start with a letter
print           'Keyword

Variables

  • All variables are of type Variant.
  • No explicit types
  • Variable get their types from the value that is assigned.

Numeric

  • Floating point: 5e-324 (negative) to 1.7976931348623157e+308 (positive)
  • Integers: reliable to 15 digits.
  • Hex: 0x500 = 1280
  • Octal: O500 = 320

Booleans

  • True or False.

Colors

  • From “#000000” to “#FFFFFF” (black to white)
  • color = (red*65536) + (green * 256) + blue

Strings

  • Maximum length depends on memory, up to 2 billion characters

Arrays

  • Dim A(9) declares an array with 10 elements
  • Dim B(8,8) creates a two dimensional array
  • Elements can be referred to as A(3), B(2,3), etc.
  • Dim statement has to be in each Code Module
  • The following notation is also OK: a[3], B[2][3}
  • Array elements do not exist until they are assigned.

Collections

  • Like an Array, but uses string values to index
Dim item1, myCollection(10)
item1="Knuth"

'Create our collection
myCollection[item1] = "firstKey"
Print myCollection[item1]  'displays firstkey

Objects

  • An object is a collection of named values, called properties
  • Customer={Name: Lovelace, Age: 195, kids:{Byron: 1, Annabella: 2, Ralph: 3}}
  • An example is Customer.name

Classes

'Define a class like this
Function Person(name, gender)
   'Add object properties like this
   this.name = name
   this.gender = gender
End Function

'Add methods like this.  All Person objects will be able to invoke this
Function speakName()
  Print "Howdy, my name is " & this.name
End Function

Person.prototype.speak = Eval("speakName")

'Instantiate new objects with 'new'
bob = new Person("Bob", "M")

'Invoke methods like this
bob.speak() 'Prints "Howdy, my name is Bob"

Control structures

Importing VB code

A few interesting statements