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 a simplified variant of the BASIC programming language, developed by Microsoft and intended as an easy programming language for beginners. The language itself has only 14 keywords,[3] and the environment is beginner-friendly, with a straightforward interface.


Small Basic was first introduced by Microsoft in October 2008[4] and was released on 13 June 2011[1] on an updated MSDN website that included a full teacher curriculum,[5] a Getting Started guide,[6] and several Small Basic e-books for beginners through a partnership with The published Small Basic guides include a complete developer's reference guide, a Beginning Small Basic tutorial, and BASIC Computer Games by David H. Ahl.[7]

Microsoft Small Basic was designed by Microsoft DevLabs and released as a Technology Preview[8] in October 2008. Its intended audience is anyone looking to begin programming, including children and beginner adults as well. Small Basic exists to help students as young as age eight[9] learn the foundations of computer programming and then graduate to Visual Basic using Visual Studio Express, where they can continue to build on the foundation by learning Visual C#, VB.NET, and Visual C++.[10]

The first trials were successfully done with several middle school children, most of them children of workers at Microsoft. Small Basic was also successfully tested using a hands-on lab approach to a group of 25 high school girls.[11]


In Small Basic, the traditional "Hello world" program is written as follows:

TextWindow.WriteLine("Hello World")

The language itself is Turing complete and supports concepts like conditional branching and loops. Variables are typeless and dynamic, and there are no scoping rules. The language supports subroutines for event handling.

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;


Microsoft Small Basic ships with a Turtle graphics library that borrows the idea from Logo. For example, the developer can make the turtle draw a square by drawing four lines and turning right after each one:

For i = 1 to 4

See also[edit]

Related Microsoft technologies:

Related languages:


  1. ^ a b "Small Basic 1.0 is here! - Small Basic - Site Home - MSDN Blogs". 2011-07-12. Retrieved 2014-02-09. 
  2. ^ a b c "Microsoft Small Basic". Downloads. Microsoft. 18 July 2011. Retrieved 16 February 2014. 
  3. ^ "What are the 14 Keywords of Small Basic? - Small Basic - Site Home - MSDN Blogs". 2012-10-08. Retrieved 2014-02-09. 
  4. ^ "Hello World - Small Basic - Site Home - MSDN Blogs". 2008-10-23. Retrieved 2014-02-09. 
  5. ^ "Small Basic Curriculum - TechNet Articles - United States (English) - TechNet Wiki". Retrieved 2014-02-09. 
  6. ^ "Small Basic Getting Started Guide - TechNet Articles - United States (English) - TechNet Wiki". Retrieved 2014-02-09. 
  7. ^ "Small Basic E-Books - TechNet Articles - United States (English) - TechNet Wiki". Retrieved 2014-02-09. 
  8. ^ "Products and Extensions for Visual Studio". Retrieved 2014-02-09. 
  9. ^ "Small Basic - Elementary & Middle Student Testimonials - Small Basic - Site Home - MSDN Blogs". 2012-10-25. Retrieved 2014-02-09. 
  10. ^ "Graduating from Small Basic - Small Basic - Site Home - MSDN Blogs". 2009-10-25. Retrieved 2014-02-09. 
  11. ^ "Expert to Expert: The Basics of SmallBasic | Charles | Channel 9". 2009-01-20. Retrieved 2014-02-09. 

External links[edit]