Software Engineers Handbook/Language Dictionary/BASIC
- 1 BASIC
- 1.1 Type
- 1.2 Execution Entry Point
- 1.3 General Syntax
- 1.4 Comments
- 1.5 Variable Declarations
- 1.6 Method Declaration/Implementation
- 1.7 Scope
- 1.8 Conditional Statements
- 1.9 Looping Statements
- 1.10 Output Statements
- 1.11 Containers
- 1.12 Algorithms
- 1.13 Garbage collection
- 1.14 Physical Structure
- 1.15 Tips
- 1.16 Web References
- 1.17 Printing
- 1.18 Books and Articles
Here is wikipedia entry.
Be warned before reading this page, that some language features here are only applicable for certain BASIC flavors.
BASIC is a full procedural language or object oriented depending on the BASIC you are using. BASIC is an acronym for Beginner's All-purpose Symbolic Instruction Code
Execution Entry Point
Modern BASICS are usually integrated into a visual, event-driven environment; in such applications, there is no program entry point in the developer's view. In the case of a command-line REALbasic program, there is a Run event of the ConsoleApplication class which is invoked when the program begins, and which receives command-line arguments as an array of strings.
BASIC syntax uses very little special punctuation, beyond those common to algebra and most other languages, such as "+" for addition. The equal sign ("=") is used for both assignment and equality testing, which raises no ambiguity since (unlike C) an assignment statement may not be used as part of another expression. Parentheses are used for grouping terms, as in algebra, as well as for indexing into arrays. A period (or dot) is used for accessing object properties or methods. Square brackets, curly braces, and other odd punctuation are not used.
Code blocks are delimited by statements; for example, an "if" block begins with an "if" statement and ends with "end if". Statements are separated by line breaks, though a statement that needs to span multiple lines can do so via a special line continuation character (" _", space followed by an underscore) and several statements can be kept in one line by using the colon (":") character, although this is usually not considered to be a good programming practice.
Here's a typical example of BASIC code:
Dim i As Integer Dim s As String for i = 1 to 4 s = s + "spam, " next MsgBox s + "baked beans, and spam!"
Both VisualBasic and REALbasic use a single apostrophe to denote a comment, which continues to the end of the line. The old REM statement may also be used, though it is no longer in fashion. REALbasic may also use C++-style "//" comments. BASIC supports no block comment mechanism, though the IDE may support quickly commenting or uncommenting blocks of code. Example:
meaning = 6*7 ' This is a comment REM So's this, but nobody writes comments this way anymore. // This comment will work only in REALbasic. ‘‘‘ In VB.NET, three apostrophes mean an XML comment.
REALbasic is a strongly-typed language; Visual Basic is more loosely typed, an untyped variable would be automatically typed as Variant-typed (VB 6 and lower) or Object-typed (VB .NET), both of them means the variable can switch types depending on the content of the variable, simulating an untyped variable. In VB.NET, there is an option to force the declaration of type. Local variables are declared using a Dim statement:
Dim i As Integer
Variable may be given initial value at declaration time. Although not for VB6.
Dim transplant As String = "liver"
Multiple variables may be declared on a single line, and they may be given initial values at declaration time, as shown here:
Dim x As Integer, xstr As String
Note that an important difference exists between REALbasic and VisualBasic when two variables are declared with only one type:
Dim a, b As Double
In REALbasic and VB.NET, both a and b would be variables of type Double. In VB 6, b would be a Double, but a would be a Variant (essentially, an untyped variable).
Note that in the case of an object declaration, there is a further shortcut for initializing the variable to a new object instance:
Dim d1 as New Date ' this... Dim d2 as Date = New Date ' does the same as this, except this is not allowed in VB6
Variables may also be declared as properties of classes, windows, or modules. These use the same syntax, or are edited directly by the IDE.
Methods are defined by a Function or Sub keyword. Here is an example.
Function Factorial( num As Integer ) As Integer Dim out As Integer = 1 Dim i As Integer For i = 2 to Num out = out * i Next i Return out End Function
REALbasic uses block scoping within a method; that is, a Dim statement within (for example) an If block makes a variable that goes out of scope at the end of that block. Local variables declared at the top of a method go out of scope at the end of the method. All variables declared within a method are inaccessible outside that method, and with the exception of static variables, use stack storage.
Properties of classes, modules, and windows are stored on the heap. Module properties may be private (accessible only within the module), public (accessible from anywhere by using the module name as a prefix), or global (accessible from anywhere with no prefix). Class properties may be private (accessible only within that class), protected (accessible within that class or its subclasses), or public (accessible from anywhere via an object reference). Windows are really just classes, and have the same scoping rules.
BASIC supports If/ElseIf/Else blocks:
If fullness < 10 Then result = "Bring me more food!" ElseIf fullness = 10 Then result = "I couldn't eat another bite." Else Explode End If
There is also a single-line format useful for quick tests:
If not haveShrubbery Then Say "Ni"
For larger blocks of tests, a Select Case may be used:
Select Case healthStage Case 0 x = "I'm not quite dead yet" Case 1 x = "I'm feeling better" Case 2 x = "Think I'll go for a walk now" Else x = "I feel happy..." End Select
BASIC sports a variety of looping constructs, including For/Next, Do/Loop, and While/Wend. The For statement may use either a numerical counter, or may iterate over the elements of an array using For Each.
For i = 1 To 100 i = i + 1 Next i
For Each knight in Knights results.Append knight.Name + " says Ni!" Next
Most BASIC applications are visual (GUI) applications, and have no standard output. However, if one just needs to display a short message, the MsgBox statement may be used:
MsgBox "Hello world!"
For debugging purposes, in REALbasic, you could also use System.DebugLog, which sends its argument to the standard debugging console for the platform you're on. In VB6, you can use Debug.Print to print a statement on the Immediate Window. In VB.NET, you can use the Debug object for various debugging options.
BASIC includes supports for arrays, which may be passed as arguments, returned from functions, assigned to variables, and so on. There is also a Collection class, and in REALbasic, a Dictionary class which holds arbitrary key/value pairs.
In cases where none of these built-in containers are suitable, one can easily define a custom container class using whatever internal storage is most appropriate.
Arrays of most primitive datatypes (e.g. numbers and strings) can be sorted (in VB.NET and REALbasic) or shuffled (REALbasic), as in this example:
Function Choose5( cards() as String ) as String() ' shuffle the given cards, choose 5 at random, ' and return them in sorted order cards.Shuffle Dim out() as String For i As Integer = 1 to 5 out.Append cards(i) Next out.Sort return out End Function
The Dictionary class (in REALbasic) provides a built-in implementation of a resizable hash table. Other algorithms may of course be written by the user as needed.
BASIC uses reference counting rather than garbage collection. When there are no more references to an object or string, its memory is automatically (and immediately) released.
Visual Basic projects are made up of a variety of files, most of them plain text. REALbasic projects are usually stored in a single-file, proprietary binary format, though it is also possible to store project items externally, in either binary or XML format.
Don't confuse Visual Basic with REALbasic and with classic BASIC (represented largely by Microsoft QuickBasic and QBASIC). They have common roots and similar syntax, but rather different semantics. REALbasic's semantics are closer to Java or VB.NET than to Visual Basic, which is more procedural than object-oriented.
In the sofware Development concept Printing is very important one specially software development for business purpose
There are two types of printing
1) Windows printing 2) Dos printing
Books and Articles
REALbasic developers should consider REALbasic Developer magazine.
Numerous books on both REALbasic and Visual Basic may be found via Amazon.com.