Small Basic: Control Character
This article illustrates about control characters for programming learners with Microsoft Small Basic.
What is Control Character
Control characters are the special characters in ASCII (American Standard Code for Information Interchange) code. In this article, BEL (bell), BS (back space), HT (horizontal tab), LF (line feed), and CR (carriage return) are treated.
char | code | char | code |
BEL | 07(7) | G | 47(71) |
BS | 08(8) | H | 48(72) |
HT | 09(9) | I | 49(73) |
LF | 0A(10) | J | 4A(74) |
CR | 0D(13) | M | 4D(77) |
Using in TextWindow
Following sample code can check the functions of the control characters BEL, BS and HT.
While "True"
TextWindow.Write(">")
txt = TextWindow.Read()
TextWindow.WriteLine(txt)
EndWhile
Run the program above and hit Ctrl+G (both [Ctrl] and [G] keys). "^G" will be displayed. This means Ctrl+G. Then hit [Enter] key. Then bell ring sound will be played.
>^G
Type any text and hit Ctrl+H. Ctrl+H works as the same as [Back Space] key.
Hit Ctrl+I. Ctrl+I works as the same as [Tab] key.
And following code shows that a new line code is CR + LF. 13 means CR, 10 means LF.
path = Program.Directory + "\test.txt"
line1 = "Small"
line2 = "Basic"
File.WriteLine(path, 1, line1)
File.WriteLine(path, 2, line2)
buf = File.ReadContents(path)
TextWindow.WriteLine(buf)
len = Text.GetLength(buf)
For p = 1 To len
c = Text.GetSubText(buf, p, 1)
TextWindow.Write(Text.GetCharacterCode(c) + " ")
EndFor
TextWindow.WriteLine("")
Small
Basic
83 109 97 108 108 13 10 66 97 115 105 99 13 10
Press any key to continue...
Using in GraphicsWindow
Following program shows HT, CR+LF or LF in 4 operations in GraphicsWindow. LF also works as a new line code.
HT = Text.GetCharacter(9)
LF = Text.GetCharacter(10)
CR = Text.GetCharacter(13)
txt[1] = "Turtle" + HT + "Graphics"
txt[2] = "Small" + CR + LF + "Basic"
txt[3] = "Hello" + LF + "World"
For i = 1 To 3
If i = 1 Then
TextWindow.WriteLine("Horizontal Tab")
ElseIf i = 2 Then
TextWindow.WriteLine("CR + LF")
Else
TextWindow.WriteLine("Line Feed")
EndIf
' 1. GraphicsWindow.DrawText
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.DrawText(10, 10, "GraphicsWindow.DrawText")
GraphicsWindow.DrawText(10, 40, txt[i])
' 2. GraphicsWindow.DrawBoundText
GraphicsWindow.DrawText(10, 110, "GraphicsWindow.DrawBoundText")
GraphicsWindow.DrawBoundText(10, 140, 100, txt[i])
' 3. Shapes.AddText
GraphicsWindow.DrawText(10, 210, "Shapes.AddText")
t = Shapes.AddText(txt[i])
Shapes.Move(t, 10, 240)
' 4. Controls.AddMultiLineTextBox
GraphicsWindow.DrawText(10, 310, "Controls.AddMultiLineTextBox")
tb = Controls.AddMultiLineTextBox(10, 340)
Controls.SetTextBoxText(tb, txt[i])
TextWindow.Write("Next? ")
a = TextWindow.Read()
GraphicsWindow.Clear()
EndFor