Microsoft Small Basic
Program Listing:
Embed this in your website
<object id='sbapp' data='data:application/x-silverlight-2,' type='application/x-silverlight-2' width='640' height='480'> <param name='source' value='http://smallbasic.com/program/ClientBin/SBWeb.xap'/> <param name='onError' value='onSilverlightError' /> <param name='background' value='white' /> <param name='minRuntimeVersion' value='3.0.40624.0' /> <param name='autoUpgrade' value='true' /> <param name='initParams' value='programId=FBT176' /> </object>
'Small Challenge 2
'Write a program to display a colorful welcome message in the GraphicsWindow
'when a button is clicked.
'==========================================================
logo
=
"Small Challenge 2"
'set variables
initFirstGUI
(
)
'MAIN PROGRAM
addGraphicsToFirstGUI
(
)
CreateButton
(
)
Controls
.
ButtonClicked
=
OnButtonClicked
waitForUser
(
)
initWelcomeGUI
(
)
addWelcome
(
)
myLogo
(
)
createEndButton
(
)
Controls
.
ButtonClicked
=
theEnd
'================================================
'Subroutines
'================================================
Sub
initFirstGUI
GraphicsWindow
.
Hide
(
)
GraphicsWindow
.
Left
=
240
GraphicsWindow
.
Top
=
140
GraphicsWindow
.
Width
=
500
GraphicsWindow
.
Height
=
300
GraphicsWindow
.
Show
(
)
GraphicsWindow
.
BackgroundColor
=
"PaleTurquoise"
GraphicsWindow
.
BrushColor
=
"Indigo"
GraphicsWindow
.
DrawText
(
375
,
5
,
logo
)
EndSub
Sub
addGraphicsToFirstGUI
GraphicsWindow
.
FontBold
=
"false"
GraphicsWindow
.
DrawText
(
20
,
285
,
"Design from: Small Basic Curriculum"
)
GraphicsWindow
.
PenColor
=
"DarkBlue"
'draw vertical line
GraphicsWindow
.
PenWidth
=
6
GraphicsWindow
.
DrawLine
(
9
,
45
,
9
,
270
)
GraphicsWindow
.
PenWidth
=
2
'draw circle
GraphicsWindow
.
PenColor
=
"Yellow"
GraphicsWindow
.
DrawEllipse
(
12
,
180
,
80
,
80
)
GraphicsWindow
.
BrushColor
=
"DeepPink"
GraphicsWindow
.
FillEllipse
(
12
,
180
,
80
,
80
)
GraphicsWindow
.
PenWidth
=
2
'draw rectangles
For
i
=
1
To
11
GraphicsWindow
.
PenColor
=
GraphicsWindow
.
GetRandomColor
(
)
GraphicsWindow
.
DrawRectangle
(
25
,
10
+
(
i
*
14
)
,
50
,
7
)
Program
.
Delay
(
100
)
EndFor
EndSub
Sub
CreateButton
GraphicsWindow
.
FontBold
=
"True"
GraphicsWindow
.
BrushColor
=
"Black"
button
=
Controls
.
AddButton
(
"Click to Run Welcome Message"
,
230
,
140
)
GraphicsWindow
.
Show
(
)
For
i
=
1
To
200
Shapes
.
SetOpacity
(
button
,
i
/
2
)
Shapes
.
Zoom
(
button
,
i
/
120
,
i
/
100
)
Shapes
.
Rotate
(
button
,
i
*
1.8
)
Program
.
Delay
(
5
)
EndFor
EndSub
Sub
OnButtonClicked
Button
=
Controls
.
LastClickedButton
Sound
.
PlayClick
(
)
EndSub
Sub
waitForUser
up
:
If
Button
<>
Controls
.
LastClickedButton
Then
Goto
up
EndIf
EndSub
Sub
initWelcomeGUI
GraphicsWindow
.
Clear
(
)
GraphicsWindow
.
Left
=
10
GraphicsWindow
.
Top
=
10
GraphicsWindow
.
Width
=
800
GraphicsWindow
.
Height
=
560
GraphicsWindow
.
BackgroundColor
=
"Black"
GraphicsWindow
.
BrushColor
=
"Gainsboro"
GraphicsWindow
.
DrawText
(
675
,
5
,
logo
)
EndSub
Sub
addWelcome
GraphicsWindow
.
FontBold
=
"True"
GraphicsWindow
.
BrushColor
=
"Lime"
elcom
=
Shapes
.
AddText
(
"elcom"
)
Shapes
.
Move
(
elcom
,
370
,
265
)
e
=
Shapes
.
AddText
(
"e"
)
Shapes
.
Move
(
e
,
370
,
265
)
For
i
=
1
To
20
Shapes
.
SetOpacity
(
e
,
i
*
5
)
Shapes
.
Zoom
(
e
,
i
/
2
,
i
/
2
)
Shapes
.
Move
(
e
,
370
+
(
i
*
11.5
)
,
265
)
Shapes
.
SetOpacity
(
elcom
,
i
*
5
)
Shapes
.
Zoom
(
elcom
,
i
/
2
,
i
/
2
)
Program
.
Delay
(
40
)
EndFor
w
=
Shapes
.
AddText
(
"W"
)
Shapes
.
Move
(
w
,
1
,
290
)
For
i
=
1
To
20
Shapes
.
Zoom
(
w
,
i
/
2
,
i
/
2
)
Shapes
.
Move
(
w
,
i
*
8
,
267
,
)
Program
.
Delay
(
20
)
EndFor
Program
.
Delay
(
100
)
Shapes
.
Move
(
elcom
,
383
,
265
)
Shapes
.
Move
(
e
,
613
,
265
)
Program
.
Delay
(
100
)
Shapes
.
Animate
(
e
,
660
,
265
,
300
)
Program
.
Delay
(
100
)
Shapes
.
Animate
(
e
,
605
,
265
,
350
)
Program
.
Delay
(
300
)
Shapes
.
Animate
(
e
,
613
,
265
,
200
)
EndSub
Sub
myLogo
GraphicsWindow
.
BrushColor
=
"Gainsboro"
GraphicsWindow
.
FontBold
=
"false"
jibba
=
Shapes
.
AddText
(
"Jibba"
)
Shapes
.
Move
(
jibba
,
-
35
,
540
)
jabba
=
Shapes
.
AddText
(
"Jabba"
)
Shapes
.
Move
(
jabba
,
740
,
540
)
Shapes
.
Animate
(
jibba
,
705
,
540
,
500
)
Program
.
Delay
(
250
)
EndSub
Sub
createEndButton
GraphicsWindow
.
BrushColor
=
"DarkRed"
GraphicsWindow
.
FontBold
=
"true"
GraphicsWindow
.
FontSize
=
15
endProgram
=
Controls
.
AddButton
(
"End Program"
,
670
,
500
)
EndSub
Sub
theEnd
If
Controls
.
LastClickedButton
=
endProgram
Then
Sound
.
PlayClickAndWait
(
)
Program
.
End
(
)
EndIf
EndSub
Copyright (c) Microsoft Corporation. All rights reserved.