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 5: Line 5:




2.2.1 Multi-Line Statements
'''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: <br />
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: <br />
Line 12: Line 12:




2.2.2 Multiple Statements per Line
'''2.2.2 Multiple Statements per Line'''
----
----
By using a ":" character as a separator, you can put more than one statement on a line:
By using a ":" character as a separator, you can put more than one statement on a line: <br />
a=1: b=2: c=3
<tt>a=1: b=2: c=3</tt>




2.2.3 Literals, Data Types and Variables
'''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.
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.
Line 24: Line 24:




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).
Line 31: Line 31:




2.2.5 Boolean Data Type
'''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.
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
'''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:
Line 55: Line 55:




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:
Line 62: Line 62:




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
Line 69: Line 69:




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:
Line 77: Line 77:




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.
Line 101: Line 101:




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.

Revision as of 02:03, 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

  1. 000000, vbBLACK

Dark gray 128, 128, 128

  1. 808080

Light gray 192, 192, 192

  1. COCOCO

White 255, 255, 255

  1. 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 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


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 'starts with a number X&Ycords 'uses special character & first counter 'has a space %correct 'does not start with a letter print 'NS Basic/App Studio keyword