Microsoft Small Basic

Program Listing: SDD265
'learning aid by Ezra94
gw = 400
gh = 400
GraphicsWindow.Height = gh
GraphicsWindow.Width = gw
GraphicsWindow.Left = (Desktop.Width-gw)/2
GraphicsWindow.Top = (Desktop.Height-gh)/4

createGUI()
Controls.ButtonClicked = onButtonClick

Sub createGUI
bw = gw/2
bh = gh/10
bx = (gw - bw)/2
by = (gh - bh)/2

mainTxtBox = Controls.AddTextBox(bx,by)
Controls.SetSize(mainTxtBox,bw,bh)

mainButton = Controls.AddButton("Enter",bx,by+bh)
Controls.SetSize(mainButton,bw,bh)

clearButton = Controls.AddButton("Clear",bx,by+bh*2)
Controls.SetSize(clearButton,bw,bh)

For i = 0 To 9
digits[i] = i
EndFor

space = 8
p = 0
EndSub

Sub onButtonClick
input = Controls.GetTextBoxText(mainTxtBox)
If (Controls.GetButtonCaption(Controls.LastClickedButton) = "Enter") Then
keyWordL = Text.GetLength(input)
For i = 1 To keyWordL
nums[i] = Text.GetSubText(input,i,1) 'breaks down input into seperate variables
For j = 0 To 9 'compare one char. w/ all digits ea. keyWordL loop
If (nums[i] <> digits[j]) Then
p = p + 1
EndIf
If (p >= 10) Then 'if true then values of nums doesn't match any digits & thus isn't a number
nums[i] = ""
space = 0
Else
space = 8
EndIf
EndFor
p = 0
GraphicsWindow.DrawText(bx,by-bh*2,nums[i])
bx = bx + space
EndFor
ElseIf (Controls.GetButtonCaption(Controls.LastClickedButton) = "Clear") Then
GraphicsWindow.Clear()
createGUI()
EndIf
EndSub