Microsoft Small Basic
≈ 6 min read
Names in other languages
No names in other languages are held for this entry yet.
Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.
Microsoft Small Basic is a programming language, interpreter and associated IDE. Microsoft's simplified variant of BASIC, it is designed to help students who have learnt visual programming languages such as Scratch learn text-based programming. The associated IDE provides a simplified programming environment with functionality such as syntax highlighting, intelligent code completion, and in-editor documentation access. The language has only 14 keywords.
Microsoft Small Basic is a programming language, interpreter and associated IDE. Microsoft's simplified variant of BASIC, it is designed to help students who have learnt visual programming languages such as Scratch learn text-based programming. The associated IDE provides a simplified programming environment with functionality such as syntax highlighting, intelligent code completion, and in-editor documentation access. The language has only 14 keywords. ==History== Microsoft announced Small Basic in October 2008, and released the first stable version for distribution on July 12, 2011, on a Microsoft Developer Network (MSDN) website, together with a teaching curriculum and an introductory guide. Between announcement and stable release, a number of Community Technology Preview (CTP) releases were made. On March 27, 2015, Microsoft released Small Basic version 1.1, which fixed a bug and upgraded the targeted .NET Framework version from version 3.5 to version 4.5, making it the first version incompatible with Windows XP. Microsoft released Small Basic version 1.2 on October 1, 2015. Version 1.2 was the first update after a four-year hiatus to introduce new features to Small Basic. The update added classes for working with Microsoft's Kinect motion sensors, increased the number of languages supported by the included Dictionary object, and fixed a number of bugs. On February 19, 2019, Microsoft announced Small Basic Online (SBO). It is open source software released under MIT License on GitHub. ==Language== 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 weakly typed and dynamic with no scoping rules. ===Conditional branching=== The following example demonstrates conditional branching. It ask the user for Celsius or Fahrenheit and then comments on the answer in the appropriate temperature unit. ' A Program that gives advice at a requested temperature. TextWindow.WriteLine("Do you use 'C'elsius or 'F'ahrenheit for temperature?") TextWindow.WriteLine("Enter C for Celsius and F for Fahrenheit:") question_temp: ' Label to jump back to input if wrong input was given tempunit = TextWindow.Read() ' Temperature Definitions in Celsius: tempArray["hot"] = 30 ' 30 °C equals 86 °F tempArray["pretty"] = 20 ' 20 °C equals 68 °F tempArray["cold"]= 15 ' 15 °C equals 59 °F If tempunit = "C" OR tempunit = "c" Then TextWindow.WriteLine("Celsius selected!") tempunit = "C" ' Could be lowercase, thus make it uppercase ElseIf tempunit = "F" OR tempunit = "f" Then TextWindow.WriteLine("Fahrenheit selected!") ' We calculate the temperature values for Fahrenheit based on the Celsius values tempArray["hot"] = ((tempArray["hot"] * 9)/5) + 32 tempArray["pretty"] = ((tempArray["pretty"] * 9)/5) + 32 tempArray["cold"] = ((tempArray["cold"] * 9)/5) + 32 tempunit = "F" ' Could be lowercase, thus make it uppercase Else GOTO question_temp ' Wrong input, jump back to label "question_temp" EndIf TextWindow.Write("Enter the temperature today (in " + tempunit +"): ") temp = TextWindow.ReadNumber() If temp >= tempArray["hot"] Then TextWindow.WriteLine("It is pretty hot.") ElseIf temp >= tempArray["pretty"] Then TextWindow.WriteLine("It is pretty nice.") ElseIf temp >= tempArray["cold"] Then TextWindow.WriteLine("Don't forget your coat.") Else TextWindow.WriteLine("Stay home.") EndIf Small Basic does not support an inline If statement as does Visual Basic, for example: If temp > 50 Then TextWindow.WriteLine("It is pretty nice.") ===Looping=== This example demonstrates a loop. Starting from one and ending with ten, it multiplies each number by four and displays the result of the multiplication. TextWindow.WriteLine("Multiplication Tables") For i = 1 To 10 TextWindow.Write(i * 4) EndFor While loops are also supported, and the demonstrated For loop can be augmented through the use of the Step keyword. The Step keyword is used in setting the value by which the counter variable, i , is incremented each iteration. ===Data types=== Small Basic supports basic data types, like strings, integers and decimals, and will readily convert one type to another as required by the situation. In the example, both the Read and ReadNumber methods read a string from the command line, but ReadNumber rejects any non-numeric characters. This allows the string to be converted to a numeric type and treated as a number rather than a string by the + operator. 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 shall be " + ( age + 5 ) + " years old!") As Small Basic will readily convert among data types, numbers can be manipulated as strings and numeric strings as numbers. This is demonstrated through the second example. 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. ==Libraries== For i = 1 To 10 pic = Flickr.GetRandomPicture("mountains") Desktop.SetWallPaper(pic) Program.Delay(10000) EndFor For i = 1 to 4 Turtle.Move(100) ' Forward 100 pixels Turtle.Turn(90) ' Turn 90 degrees right EndFor More complex drawings are possible by altering the turning angle of the turtle and the number of iterations of the loop. For example, one can draw a hexagon by setting the turn angle to 60 degrees and the number of iterations to six. [SmallBasicType] public static class ExampleClass { public static Primitive Add(Primitive A, Primitive B) => A + B; public static Primitive SomeProperty { get; set; } public static Primitive Pi => (Primitive)3.14159; } If available, the Small Basic development environment will display documentation for third-party libraries. The development environment accepts documentation in the form of an XML file, which can be automatically generated from source code comments by tools such as Microsoft Visual Studio and MonoDevelop. ==References== ==External links==
Text derived from https://en.wikipedia.org/w/index.php?oldid=1320955187 under CC BY-SA 4.0; modifications have been made.
References
2 claims could not be tied to a specific sentence and are listed in the table below instead.