Partager via


Small Basic #19: Syntax Cheat Sheet

Here's my list of how to create and access things in Small Basic. I use this when I need to jog my memory but don't want to search through the Introducing Small Basic guide.

Create

Array:

 myArray[1] = "myString"
TextWindow.WriteLine(Array.GetItemCount(myArray))

Directory:

 File.CreateDirectory("C:\temp\myTempDir")

Ellipse:

 GraphicsWindow.DrawEllipse(10, 15, 75, 25)
 ' Or...
 myEllipse = Shapes.AddEllipse(100, 50)

Flickr image:

 GraphicsWindow.DrawImage(Flickr.GetPictureOfMoment(), 0, 0)

For statement:

 For i = 1 To 10
    TextWindow.WriteLine(i)
EndFor

If/Then statement:

 If Clock.Year = 2010 Then
    TextWindow.WriteLine("2010")
Else
    TextWindow.WriteLine("Not 2010")  
EndIf 

Image:

 myImage = Shapes.AddImage(ImageList.LoadImage("https://www.microsoft.com/about/images/home_blue.jpg"))

Label:

 Goto myLabel
 myLabel:
    TextWindow.WriteLine("Hello, World!")

Line:

 GraphicsWindow.DrawLine(10, 20, 100, 50)
 ' Or...
 myLine = Shapes.AddLine(15, 20, 40, 65) 

Rectangle:

 GraphicsWindow.DrawRectangle(5, 15, 80, 35)
 ' Or...
 
myRectangle = Shapes.AddRectangle(50, 35)

Shape:

 myEllipse = Shapes.AddEllipse(100, 50)

Stack:

 Stack.PushValue("myStack", "myValue")
TextWindow.WriteLine(Stack.PopValue("myStack"))

Subroutine:

 mySub()
 Sub mySub
    TextWindow.WriteLine("Hello, World!")
EndSub

Triangle:

 GraphicsWindow.DrawTriangle(10, 15, 50, 100, 75, 25)
 ' Or...
 
myTriangle = Shapes.AddTriangle(30, 10, 100, 75, 145, 35)

Access

Clock functions:

 TextWindow.WriteLine(Clock.Date)

Desktop:

 TextWindow.WriteLine(Desktop.Height)

Dictionary:

 TextWindow.WriteLine(Dictionary.GetDefinition("banana"))

File functions:

 TextWindow.WriteLine(File.GetTemporaryFilePath())

Graphics window:

 GraphicsWindow.DrawBoundText(20, 10, 80, "Hello, World!")

Image:

 GraphicsWindow.DrawImage(ImageList.LoadImage("https://www.microsoft.com/about/images/home_blue.jpg"), 0, 0)

Image list:

 TextWindow.WriteLine(ImageList.GetHeightOfImage(ImageList.LoadImage("https://www.microsoft.com/about/images/home_blue.jpg")))

Math functions:

 TextWindow.WriteLine(Math.SquareRoot(25))

Mouse:

 GraphicsWindow.MouseDown = OnMouseDown
 Sub OnMouseDown
    If Mouse.IsLeftButtonDown Then
        GraphicsWindow.Title = "Left button pressed"
    Else  
        GraphicsWindow.Title = "Left button not pressed"
    EndIf 
EndSub

Network functions:

 TextWindow.WriteLine(Network.GetWebPageContents("https://www.microsoft.com/"))

Program functions:

 TextWindow.WriteLine(Program.Directory)

Sound functions:

 Sound.PlayBellRingAndWait()

Stack:

 Stack.PushValue("myStack", "myValue")
TextWindow.WriteLine(Stack.PopValue("myStack"))

Text functions:

 TextWindow.WriteLine(Text.GetLength("myText"))

Text window:

 TextWindow.WriteLine("Hello, World!")

Timer:

 Timer.Tick = OnTick
Timer.Interval = 5000
 Sub OnTick
    TextWindow.WriteLine(Clock.Time)  
EndSub

Turtle:

 Turtle.Move(100) 

Comments

  • Anonymous
    January 09, 2011
    Thank you for API examples ! It' is very good to make an introduction to lesson Small basic for 7 to 77 years old like TinTin

  • Anonymous
    August 26, 2011
    The comment has been removed

  • Anonymous
    March 06, 2016
    Hi! If anyone has questions, please ask in the Small Basic forum: social.msdn.microsoft.com/.../threads Thank you!