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
Designed by Microsoft, Vijaye Raji
Developer Microsoft
First appeared July 13, 2011; 4 years ago (2011-07-13)[1]
Stable release v1.1 / March 27, 2015; 5 months ago (2015-03-27)[2]
Typing discipline Dynamic, weak
Platform .NET Framework 4.5[2]
OS Windows Vista, Windows 7, Windows 8, Windows 8.1, Windows 10, Windows Server 2008 R2[2]
License Freeware
Filename extensions .sb
Influenced by
Visual Basic .NET

Microsoft Small Basic is a programming language and associated IDE. It is Microsoft's simplified variant of the BASIC programming language, intended as an easy programming language for beginners. The associated IDE provides a simplified programming environment with functionality such as syntax highlighting, intelligent code completion, and in-editor documentation access.[4] The language has only 14 keywords.[5]


Microsoft announced Small Basic in October 2008[6] and on 13 June 2011 released it for distribution[1] on a Microsoft Developer Network (MSDN) website together with a teaching curriculum[7] and an introductory guide.[8]

On March 27, 2015, Microsoft released Small Basic version 1.1,[2] which fixed a bug and upgraded the targeted .NET Framework version from version 3.5 to version 4.5.


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)

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 d "Small Basic 1.1 is here!". Small Basic MSDN Blog. Microsoft. 27 March 2015. Retrieved 12 August 2015. 
  3. ^
  4. ^ Price, Ed (22 October 2012). "The Unique Features of Small Basic". Small Basic. TechNet. Microsoft. Retrieved 22 April 2015. 
  5. ^ Price, Ed (8 October 2012). "What are the 14 Keywords of Small Basic?". Small Basic. MSDN Blogs. Microsoft. Retrieved 9 February 2014. 
  6. ^ Raji, Vijaye (23 October 2008). "Hello World". Small Basic. MSDN Blogs. Microsoft. Retrieved 9 February 2014. 
  7. ^ Price, Ed (29 April 2014). "Small Basic Curriculum". TechNet. Microsoft. Retrieved 9 February 2014. 
  8. ^ Price, Ed; Takahashi, Nonki (25 February 2014). "Small Basic Getting Started Guide". TechNet. Microsoft. Retrieved 12 February 2015. 

External links[edit]