Microsoft Small Basic

From Wikipedia, the free encyclopedia
Jump to: navigation, search
This article is about the Microsoft programming language. For the GPL programming language, see SmallBASIC.
Microsoft Small Basic
Microsoft Small Basic icon.png
Small Basic.png
Small Basic running on Windows 7
Paradigm Structured, imperative, object-oriented
Developer Microsoft
Appeared in July 13, 2011; 3 years ago (2011-07-13)[1]
v1.0 / July 18, 2011; 3 years ago (2011-07-18)[2]
Platform .NET Framework 3.5 SP1[2]
OS Windows XP, Windows Vista, Windows 7, Windows Server 2003, Windows Server 2008[2]
License Freeware

Microsoft Small Basic is Microsoft's simplified variant of the BASIC programming language, intended as an easy programming language for beginners. The language has only 14 keywords.[3]


Microsoft announced Small Basic in October 2008[4] and on 13 June 2011 released it for distribution[1] on a Microsoft Developer Network (MSDN) website together with a teaching curriculum[5] and an introductory guide.[6] A developer's reference, three semesters of self-study tutorials, BASIC Computer Games: Small Basic Edition by David H. Ahl, Ahl's Small Basic Computer Adventures, and Computer Bible Games for Microsoft Small Basic are available for purchase from Kidware Software.[7][8]


In Small Basic, one writes the illustrative "Hello, world!" program as follows:

TextWindow.WriteLine("Hello World!")

Microsoft Small Basic is Turing complete. It supports conditional branching, loop structures, and subroutines for event handling. Variables are typeless and dynamic with no scoping rules.

Conditional branching[edit]

The following example demonstrates conditional branching. It requests the current temperature in Fahrenheit and comments on the answer.

TextWindow.Write("Enter the temperature today (in F): ")
temp = TextWindow.ReadNumber()
If temp > 100 Then
  TextWindow.WriteLine("It is pretty hot.")
ElseIf temp > 70 Then
  TextWindow.WriteLine("It is pretty nice.")
ElseIf temp > 50 Then
  TextWindow.WriteLine("Don't forget your coat.")
  TextWindow.WriteLine("Stay home.")


This example demonstrates a loop. Starting from one and ending with ten, it multiplies each number by four and displays the result of multiplication.

TextWindow.WriteLine("Multiplication Tables")
For i = 1 To 10
  TextWindow.Write(i * 4)
End For

Data types[edit]

The language supports basic implementation of data types, like strings, integers and decimals.

In this example, the program requests the user's name and age and then tells the user how old he would be in five years. However, it treats the age as a number and won't accept characters in age.

TextWindow.WriteLine("Enter your name:")
name = TextWindow.Read()
TextWindow.Write("Enter your age: ")
age = TextWindow.ReadNumber()
TextWindow.WriteLine("Hello " + name + "!")
TextWindow.WriteLine("In 5 years you will be " + ( age + 5 ) + " years old!")

Small Basic stores all values – including arrays – as formatted strings.[citation needed] Hence, strings containing numerical data can be manipulated as numbers in various contexts, and vice versa:

TextWindow.WriteLine(Math.log("100")) 'Prints 2
TextWindow.WriteLine("100" + "3000") ' Prints 3100
TextWindow.WriteLine("Windows " + 8) ' Prints Windows 8
TextWindow.WriteLine(Text.GetLength(1023.42)) ' Prints 7 (length of decimal representation including decimal point)

In the second example, both strings are treated as numbers and added together, producing the output 3100. To concatenate the two values, producing the output 1003000, it is necessary to use the Text.Append(text1, text2) method.


Standard library[edit]

Small Basic ships with a standard library that is fairly extensive, considering the language is intended to be used to learn, rather than to develop production-grade applications. This standard library has the basic classes you would expect from a library, such as the ability to create and read files, as well as a "Turtle" class, similar to Logo, and the ability to retrieve images from Flickr.

As this is a language for learning, the process of retrieving images from Flickr has been vastly simplified, as demonstrated in the Small Basic code below.

For i = 1 To 10
  pic = Flickr.GetRandomPicture("mountains")

Third-party libraries[edit]

Small Basic also allows the use of libraries created by a third party. These libraries must be written in a CLR-compatible language, and the classes that are intended for use with Small Basic must be static, and must be flagged with an attribute showing that Small Basic is to use them. Functions, properties, and variables within these classes must return a "Primitive" structure, which is contained within the Small Basic standard library.

An example of a class to be used in Small Basic is provided below, written in C#.

public static class ExampleSBClass
  public static Primitive Add(Primitive A, Primitive B)
    return A + B;
  public static Primitive SomeProperty { get; set; }
  public static Primitive Pi
      return (Primitive)3.14159;

Turtle graphics[edit]

Microsoft Small Basic ships with a Turtle graphics library that borrows the idea from Logo. For example, the developer of a Small Basic program can draw a square by moving the turtle forward x pixels (in the example below, x is 100) to draw a line segment, then turning the turtle 90 degrees to the right, and iterating this procedure four times:

For i = 1 to 4

See also[edit]

Related Microsoft technologies:

Related languages:


  1. ^ a b Aldana, Sandra (7 December 2011). "Small Basic 1.0 is here!". Small Basic. MSDN Blogs. Microsoft. Retrieved 9 February 2014. 
  2. ^ a b c "Microsoft Small Basic". Download Center. Microsoft. 18 July 2011. Retrieved 16 February 2014. 
  3. ^ Price, Ed (8 October 2012). "What are the 14 Keywords of Small Basic?". Small Basic. MSDN Blogs. Microsoft. Retrieved 9 February 2014. 
  4. ^ Raji, Vijaye (23 October 2008). "Hello World". Small Basic. MSDN Blogs. Microsoft. Retrieved 9 February 2014. 
  5. ^ Price, Ed (29 April 2014). "Small Basic Curriculum". TechNet. Microsoft. Retrieved 9 February 2014. 
  6. ^ Price, Ed; Takahashi, Nonki (25 February 2014). "Small Basic Getting Started Guide". TechNet. Microsoft. Retrieved 12 February 2015. 
  7. ^ Price, Ed (12 May 2014). "Small Basic Programming Books". TechNet. Microsoft. Retrieved 12 February 2015. 
  8. ^ "Small Basic". Computer Science For Kids. Kidware Software. 2014. 

External links[edit]