The Elements of an NSB/App Studio Program: Difference between revisions

From NSB App Studio
Jump to navigation Jump to search
No edit summary
No edit summary
Line 26: Line 26:
'''2.2.4 Numeric Data Types'''
'''2.2.4 Numeric Data Types'''
----
----
All numbers in NS Basic/App Studio are internally stored as 64bit (8 bytes) floating point numbers, yielding an effective range of 5e-324 (negative) to 1.7976931348623157e+308 (positive).
All numbers in NS Basic/App Studio are internally stored as 64bit (8 bytes) floating point numbers, yielding an effective range of 5e-324 (negative) to 1.7976931348623157e+308 (positive). <br />
Integers are considered reliable (numbers without a period or exponent notation) to 15 digits (9e15). Floating point numbers are considered only as reliable as possible and no more. This is an especially important concept to understand for currency manipulation as 0.06 + 0.01 resolves to 0.06999999999999999 instead of 0.07.
Integers are considered reliable (numbers without a period or exponent notation) to 15 digits (9e15). Floating point numbers are considered only as reliable as possible and no more. This is an especially important concept to understand for currency manipulation as 0.06 + 0.01 resolves to 0.06999999999999999 instead of 0.07. <br />
Hex values are expressed with a leading 0x. Octal values just have a leading 0. So, 0x500 = 1280, while 0500 = 320.
Hex values are expressed with a leading 0x. Octal values just have a leading 0. So, 0x500 = 1280, while 0500 = 320.


Line 38: Line 38:
'''2.2.6 Color Data Type'''
'''2.2.6 Color Data Type'''
----
----
Colors are hex strings from “#000000” to “#FFFFFF”. A color value is created by mixing values for red, green, and blue that vary from 0 to 255, where 0 is dark and 255 if bright. The mixing formula is:
Colors are hex strings from “#000000” to “#FFFFFF”. A color value is created by mixing values for red, green, and blue that vary from 0 to 255, where 0 is dark and 255 if bright. The mixing formula is: <br />
color = (red*65536) + (green * 256) + blue
::<tt>color = (red*65536) + (green * 256) + blue</tt> <br />
Shades of black and white are created when equal amounts of red, green, and blue are used. See Appendix A for a list of common color constants. Color Name Red, Green, Blue Color Value
Shades of black and white are created when equal amounts of red, green, and blue are used. See Appendix A for a list of common color constants.
Black
{| class = "wikitable"
0, 0, 0
|-
#000000, vbBLACK
! Color Name !! Red, Green, Blue !! Color Value
Dark gray
|-
128, 128, 128
| Black || 0, 0, 0 || #000000, vbBLACK
#808080
|-
Light gray
| Dark gray || 128, 128, 128 || #808080
192, 192, 192
|-
#COCOCO
| Light gray || 192, 192, 192 || #COCOCO
White
|-
255, 255, 255
| White || 255, 255, 255 || #FFFFFF vbWHITE
#FFFFFF vbWHITE




'''2.2.7 String Data Type'''
'''2.2.7 String Data Type'''
----
----
Strings consist of a series of characters. A string can be approximately 2 billion characters long. There are a number of functions that manipulate strings. The concatenation operator (&) is used to join the string representations of two variables together. A string literal is enclosed in quotation marks:
Strings consist of a series of characters. A string can be approximately 2 billion characters long. There are a number of functions that manipulate strings. The concatenation operator (&) is used to join the string representations of two variables together. A string literal is enclosed in quotation marks: <br />
"This is a string literal"
<tt>"This is a string literal"</tt>
 
Strings are 1 indexed: the first character of a string is character 1 in NS Basic/App Studio string functions. Strings are enclosed in double quotes. A single quote(‘) is allowed inside a string. Use two double quotes ("") inside a quoted string to get a single double quote in the string.
Strings are 1 indexed: the first character of a string is character 1 in NS Basic/App Studio string functions. Strings are enclosed in double quotes. A single quote(‘) is allowed inside a string. Use two double quotes ("") inside a quoted string to get a single double quote in the string.


Line 64: Line 64:
'''2.2.8 Array Data Type'''
'''2.2.8 Array Data Type'''
----
----
Arrays are lists of values stored with a single name. Each element in the array is referred to by a number or a string in square brackets after the variable name. The first element of an array is always zero (0), and each array can have many elements. ARR[2] refers to the third element in the ARR array. Each element in an array
Arrays are lists of values stored with a single name. Each element in the array is referred to by a number or a string in square brackets after the variable name. The first element of an array is always zero (0), and each array can have many elements. ARR[2] refers to the third element in the ARR array. Each element in an array can be of any variable type, including another array. Parenthesis can be used instead of square brackets in most cases.
NS Basic/App Studio Handbook 11
can be of any variable type, including another array. Parenthesis can be used instead of square brackets in most cases.




'''2.2.9 Object Data Type'''
'''2.2.9 Object Data Type'''
----
----
An object is a collection of named values, called properties. To refer to a property of an object, use the object name, a period and the property name:
An object is a collection of named values, called properties. To refer to a property of an object, use the object name, a period and the property name: <br />
Customer.Name
:<tt>Customer.Name</tt> <br />
An object have any number of properties. Properties can be any datatype, including functions and other objects.
An object have any number of properties. Properties can be any datatype, including functions and other objects. <br />
Customer={Name: Lovelace, Age: 195, kids:{Byron: 1, Annabella: 2, Ralph: 3}}
<tt>Customer={Name: Lovelace, Age: 195, kids:{Byron: 1, Annabella: 2, Ralph: 3}}</tt>




'''2.2.10 Collections'''
'''2.2.10 Collections'''
----
----
A collection is an object used for grouping and managing related objects. It functions like an array, but with strings instead of numbers identifying elements in the array.
A collection is an object used for grouping and managing related objects. It functions like an array, but with strings instead of numbers identifying elements in the array. <br />
Dim item1, item2, item3, item4
<tt>Dim item1, item2, item3, item4 <br />
item1="Knuth"
item1="Knuth" <br />
item2="Babbage"
item2="Babbage" <br />
item3="Kemeny"
item3="Kemeny" <br />
item4="Kurtz"
item4="Kurtz"
'Create our collection
 
myCollection = new Object()
'Create our collection <br />
myCollection.add(item1, "firstKey")
myCollection = new Object() <br />
myCollection.add(item2, "secondKey")
myCollection.add(item1, "firstKey") <br />
myCollection.add(item3, "thirdKey")
myCollection.add(item2, "secondKey") <br />
myCollection.add(item3, "thirdKey") <br />
myCollection.add(item4, "fourthKey")
myCollection.add(item4, "fourthKey")
Print "After adding using myCollection.add(item, key):"
 
For Each key, item in myCollection
Print "After adding using myCollection.add(item, key):" <br />
Print key & "=" & item
For Each key, item in myCollection <br />
Next
:Print key & "=" & item <br />
Print "myCollection[item1]=" & myCollection[item1]
Next <br />
Print "myCollection[item1]=" & myCollection[item1] <br />
Print "myCollection[""Knuth""]=" & myCollection["Knuth"]
Print "myCollection[""Knuth""]=" & myCollection["Knuth"]
'Delete a member
 
myCollection.delete(item2)
'Delete a member <br />
myCollection.delete(item2)</tt>




'''2.2.11 Variable Names'''
'''2.2.11 Variable Names'''
----
----
A variable is a name that holds a value. The name consists of a sequence of alphabetic and numeric characters, and the underscore (_) characters. There is no limit to the length of a variable name in NS Basic/App Studio, and every character in the name is significant. (Some older BASICs could only use short names.) Variable names are not case sensitive, and spaces and other special characters may not be used. Variable names must start with a letter. NS Basic/App Studio constants may not be used as variable names. For a complete list of constants, see Appendix B.
A variable is a name that holds a value. The name consists of a sequence of alphabetic and numeric characters, and the underscore (_) characters. There is no limit to the length of a variable name in NS Basic/App Studio, and every character in the name is significant. (Some older BASICs could only use short names.) Variable names are not case sensitive, and spaces and other special characters may not be used. Variable names must start with a letter. NS Basic/App Studio constants may not be used as variable names. For a complete list of constants, see Appendix B. <br />
The following list shows some variable names that are allowed by NS Basic/App Studio:
The following list shows some variable names that are allowed by NS Basic/App Studio: <br />
text
text <br />
LLAMAS 'same as llamas or Llamas
LLAMAS &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'same as llamas or Llamas <br />
Jupiter
Jupiter <br />
W1Spec
W1Spec <br />
SouthPark
SouthPark
And some that are not allowed:
 
1table 'starts with a number
And some that are not allowed: <br />
X&Ycords 'uses special character &
1table &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 'starts with a number <br />
first counter 'has a space
X&Ycords &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 'uses special character & <br />
%correct 'does not start with a letter
first counter &nbsp&nbsp 'has a space <br />
print 'NS Basic/App Studio keyword
%correct &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 'does not start with a letter <br />
print &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 'NS Basic/App Studio keyword

Revision as of 02:16, 1 August 2012

A program in NS Basic/App Studio is a set of Statements. Each NS Basic/App Studio program line may consist of the following elements:
KEYWORD arguments 'comment
A KEYWORD is a word from the language that NS Basic/App Studio understands. Examples are PRINT, INPUTBOX and IF. The Statement and its arguments determine what action (if any) will be taken by NS Basic/App Studio when the line is executed.
Any text following ' on a line is a comment, and is ignored by NS Basic/App Studio.


2.2.1 Multi-Line Statements


Each NS Basic/App Studio statement normally ends at the end of the statement line. If you have a very complex statement the line can be very long. This can make your programs difficult to read. You may split long statements by using the line-continuation sequence, a space followed by an underscore, ( _) at the end of the line. NS Basic/App Studio combines the current line with the next line if the current line ends in ( _). Here is an example of line continuation:
PRINT "Long statements are no problem for"_

& " NS Basic/App Studio"


2.2.2 Multiple Statements per Line


By using a ":" character as a separator, you can put more than one statement on a line:
a=1: b=2: c=3


2.2.3 Literals, Data Types and Variables


Literals are literal values you use in your programs. You use them all the time: to set the initial value of a variable, to establish the starting and ending values of a FOR...NEXT loop, and so on. When you define a constant using the CONST Statement, the name of your constant can be treated as a literal. You cannot change the value of a literal.
Variables are the named holders of your data. A variable's value may be changed as needed. All variables are of variants, which means they assume the type of the value that is assigned to them. The type of a variable can change without restriction.


2.2.4 Numeric Data Types


All numbers in NS Basic/App Studio are internally stored as 64bit (8 bytes) floating point numbers, yielding an effective range of 5e-324 (negative) to 1.7976931348623157e+308 (positive).
Integers are considered reliable (numbers without a period or exponent notation) to 15 digits (9e15). Floating point numbers are considered only as reliable as possible and no more. This is an especially important concept to understand for currency manipulation as 0.06 + 0.01 resolves to 0.06999999999999999 instead of 0.07.
Hex values are expressed with a leading 0x. Octal values just have a leading 0. So, 0x500 = 1280, while 0500 = 320.


2.2.5 Boolean Data Type


Booleans consists of two values: TRUE and FALSE. This data type is used with the IF Statement. It tests the Boolean value of an expression and selects the THEN Statement if it is TRUE, or the ELSE Statement if it is FALSE. The numeric value for TRUE is -1, and the numeric value for FALSE is 0.


2.2.6 Color Data Type


Colors are hex strings from “#000000” to “#FFFFFF”. A color value is created by mixing values for red, green, and blue that vary from 0 to 255, where 0 is dark and 255 if bright. The mixing formula is:

color = (red*65536) + (green * 256) + blue

Shades of black and white are created when equal amounts of red, green, and blue are used. See Appendix A for a list of common color constants.

Color Name Red, Green, Blue Color Value
Black 0, 0, 0 #000000, vbBLACK
Dark gray 128, 128, 128 #808080
Light gray 192, 192, 192 #COCOCO
White 255, 255, 255 #FFFFFF vbWHITE


2.2.7 String Data Type


Strings consist of a series of characters. A string can be approximately 2 billion characters long. There are a number of functions that manipulate strings. The concatenation operator (&) is used to join the string representations of two variables together. A string literal is enclosed in quotation marks:
"This is a string literal"

Strings are 1 indexed: the first character of a string is character 1 in NS Basic/App Studio string functions. Strings are enclosed in double quotes. A single quote(‘) is allowed inside a string. Use two double quotes ("") inside a quoted string to get a single double quote in the string.


2.2.8 Array Data Type


Arrays are lists of values stored with a single name. Each element in the array is referred to by a number or a string in square brackets after the variable name. The first element of an array is always zero (0), and each array can have many elements. ARR[2] refers to the third element in the ARR array. Each element in an array can be of any variable type, including another array. Parenthesis can be used instead of square brackets in most cases.


2.2.9 Object Data Type


An object is a collection of named values, called properties. To refer to a property of an object, use the object name, a period and the property name:

Customer.Name

An object have any number of properties. Properties can be any datatype, including functions and other objects.
Customer={Name: Lovelace, Age: 195, kids:{Byron: 1, Annabella: 2, Ralph: 3}}


2.2.10 Collections


A collection is an object used for grouping and managing related objects. It functions like an array, but with strings instead of numbers identifying elements in the array.
Dim item1, item2, item3, item4
item1="Knuth"
item2="Babbage"
item3="Kemeny"
item4="Kurtz"

'Create our collection
myCollection = new Object()
myCollection.add(item1, "firstKey")
myCollection.add(item2, "secondKey")
myCollection.add(item3, "thirdKey")
myCollection.add(item4, "fourthKey")

Print "After adding using myCollection.add(item, key):"
For Each key, item in myCollection

Print key & "=" & item

Next
Print "myCollection[item1]=" & myCollection[item1]
Print "myCollection[""Knuth""]=" & myCollection["Knuth"]

'Delete a member
myCollection.delete(item2)


2.2.11 Variable Names


A variable is a name that holds a value. The name consists of a sequence of alphabetic and numeric characters, and the underscore (_) characters. There is no limit to the length of a variable name in NS Basic/App Studio, and every character in the name is significant. (Some older BASICs could only use short names.) Variable names are not case sensitive, and spaces and other special characters may not be used. Variable names must start with a letter. NS Basic/App Studio constants may not be used as variable names. For a complete list of constants, see Appendix B.
The following list shows some variable names that are allowed by NS Basic/App Studio:
text
LLAMAS         'same as llamas or Llamas
Jupiter
W1Spec
SouthPark

And some that are not allowed:
1table &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 'starts with a number
X&Ycords &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 'uses special character &
first counter &nbsp&nbsp 'has a space
%correct &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 'does not start with a letter
print &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 'NS Basic/App Studio keyword