integrated development environment (IDE), 4–6 defined, 4 Edi<strong>to</strong>r, 4 Help Area, 5 Surface, 5 Toolbar, 5 IntelliSense, 9 naming variables, 48–49 interactive programs, 73 IsArray() method, 232–233 IsArray.sb, 232 IsSubText() method, 265 iteration statements, 97 J JackHouse_Incomplete.sb, 281 JoinNum.sb, 18 JoinString.sb, 18 .jpg files, 289 jump statements, 97 K KeyDown event handler, 153 KeyDown.sb, 152–154 keywords, 9 KnockKnock.sb, 54 L labels, 107 LandArea.sb, 131 LastClickedBut<strong>to</strong>n property, 170 library, 4 lines, drawing, 28–29 Lines.sb, 186 LinkedIn, 227 LoadImage() method, 191 logical expressions, 99 logical opera<strong>to</strong>rs, 115–120 logic errors, 25 LogicError.sb, 53 LoginName.sb, 297 lookup tables, 228 loops, 98 accumula<strong>to</strong>r, 184–185 control variables, 183 counter, 183 defined, 107 infinite, 199–200 iteration of, 182 For loops. See For loops nested, 67–68, 189–190 Step size, 187 terminal value of, 182 While, 195–205 M machine language, 2 MagicBall.sb, 217–218 Magician.sb, 81 MakeLine1() subroutine, 238 MakeLine2() subroutine, 238 MakeLine3() subroutine, 238 maps, 208, 228 math, 17–18 Math object, 83. See also numbers Abs() method, 88–89 Ceiling() method, 86–87 exponent methods, 84–86 Floor() method, 86–88 GetRandomNumber() method, 92, 125 Max() method, 88–89 Min() method, 88–89 Power() method, 85–86 Remainder() method, 90–91 rounding methods, 86–88 Round() method, 78, 86–88 SquareRoot() method, 84–85 trigonometric methods, 93–94 math opera<strong>to</strong>rs, 83 Math.Round() method, 78, 133 Math Wizard program, 302–304 Max() method, 88–89 Maze_Incomplete.sb, 163 methods, 7, 15 passing variables <strong>to</strong>, 45 Min() method, 88–89 misspelled words, 277–278 MoeMows.sb, 231–232 Money.sb, 90 MouseDown event, 152, 154, 157, 173, 201 MouseMove event, 155–156, 157 MouseUp event, 157 MouseX property, 152, 156 MouseY property, 152, 156 MoveApples() subroutine, 221–222 MoveKnight() subroutine, 143–144 Move() method, 56, 60, 62–63, 121–122, 246 MoveTo() method, 57–58 Index 313
MovingWord.sb, 184 .mp3 files, 289 multiline strings, 272–273 multiple nesting, 191–192 N naming programs, 8 nested If/Else statements, 104–106 nested If statements, 104–106 nested loops, 67–68, 189–190 NestedLoops.sb, 189–190 nested subroutines, 135–137 nesting, 189 NewGame() subroutine, 141, 255–256 NewRound() subroutine, 160–161 not equal opera<strong>to</strong>r (), 101 Notepad, 291 numbers, 53. See also Math object averaging, 78–79 displaying, 17–18 random, 92 reading, 74 O objects Array, 232–235 Controls, 166–169 File, 291–301 GraphicsWindow, 10, 28, 60, 133 ImageList, 191 Math. See Math object properties of, 18–19 Shapes, 120–122, 159, 246 Text. See Text object TextWindow, 7, 15, 16, 20 Okla.sb, 260–261 OnBut<strong>to</strong>nClicked() subroutine, 168, 170, 237–238, 258–260, 282–283 OnGameOver() subroutine, 161 OnKeyDown() subroutine, 153, 159, 160 OnMouseDown() subroutine, 152, 157, 173, 174, 201, 202 OnMouseMove() subroutine, 156, 170 OnTextTyped() subroutine, 175 OnTick handler, 159, 160 opening files, 5 operands, 22, 101–102, 117 opera<strong>to</strong>rs arithmetic, 22–23 relational, 100–101, 120 OrDemo.sb, 119 Or opera<strong>to</strong>r, 118–119 output files, 288 P palindromes, 274–275 Palindrome.sb, 275 ParallelLines.sb, 28 pathname, 290 Pause() method, 76–77, 144 PauseWithoutMessage() method, 77 .pdb (program database) files, 8 .pdf files, 289 pen, 34–35 PenColor property, 60, 170 PenDown() method, 56 PentaStar.sb, 65–66 PenUp() method, 56 PenWidthDemo.sb, 34–35 PenWidth property, 60 PepperDare.sb, 136–137 persistent data, 288 Pick() subroutine, 136 pig latin, 276 PigLatin.sb, 276 Pinball.sb, 223–224 Poet.sb, 235–239 CreateLists() subroutine, 301 graphical user interface, 237 MakeLine1() subroutine, 238 MakeLine2() subroutine, 238 MakeLine3() subroutine, 238 OnBut<strong>to</strong>nClicked() subroutine, 237–238 startup file, 236, 302 polling, 202 polygon art, 67–68 PolygonArt.sb, 69 polygons, drawing, 64–70 Polygon.sb, 65 PowerDemo.sb, 85 Power() method, 85–86 ProcessChoice() subroutine, 143 program database (.pdb) files, 8 programmers, 2 programming errors, 24–25 logic errors, 25 runtime errors, 25 syntax errors, 24 programs compiling, 6 naming, 8 314 Index
- Page 1 and 2:
Learn to Program with Small Basic A
- Page 4 and 5:
Learn to Program with Small Basic A
- Page 6:
Brief Contents Foreword by Vijaye R
- Page 9 and 10:
Exploring Other Features. .........
- Page 11 and 12:
7 Empowering Programs with math 83
- Page 13 and 14:
12 building Graphical User Interfac
- Page 15 and 16:
Storing Records. ..................
- Page 18 and 19:
Foreword Computer programming is ma
- Page 20 and 21:
Acknowledgments This book represent
- Page 22 and 23:
Introduction Have you ever wondered
- Page 24 and 25:
• In Chapter 11: Event-Driven Pro
- Page 26 and 27:
1 Introducing Small Basic Bill Gate
- Page 28 and 29:
BASIC language that would help kids
- Page 30 and 31:
Toolbar Help Area Editor Surface Fi
- Page 32 and 33:
Then click the New button to open a
- Page 34 and 35:
Helping Hands: IntelliSense and Syn
- Page 36:
Programming Challenges If you get s
- Page 39 and 40:
The Parts of a Program Let’s expl
- Page 41 and 42:
The method’s name and a brief des
- Page 43 and 44:
5 + 7 12 Here’s the output of thi
- Page 45 and 46:
For example, to make the TextWindow
- Page 47 and 48:
TRY IT OUT 2-3 Now you have a chanc
- Page 49 and 50:
Programming Errors Just because a p
- Page 51 and 52:
26 Chapter 2 4. Write a program tha
- Page 53 and 54:
In the system you use at school, po
- Page 55 and 56:
Drawing Shapes You can draw lots of
- Page 57 and 58:
Figure 3-6 shows what the output lo
- Page 59 and 60:
22 GraphicsWindow.BrushColor = "Lig
- Page 61 and 62:
DrawText() takes three arguments. T
- Page 63 and 64:
GraphicsWindow provides two methods
- Page 65 and 66:
6. Write a program that draws this
- Page 68 and 69:
4 Using Variables Have you ever wan
- Page 70 and 71:
Try changing the value in karenBear
- Page 72 and 73:
These two ways of updating the scor
- Page 74 and 75:
Figure 4-2: How a variable is added
- Page 76 and 77:
TRY IT OUT 4-3 Write a program that
- Page 78 and 79:
Two Kinds of Data Programs use all
- Page 80 and 81:
5 Drawing Shapes with Turtle Graphi
- Page 82 and 83:
Absolute Motion With absolute motio
- Page 84 and 85:
North 0 (360) 315 (-45) 45 (-315) W
- Page 86 and 87:
GraphicsWindow.PenColor = "Red" Gra
- Page 88 and 89:
The For loop runs Turtle.Move(60) a
- Page 90 and 91:
y 5). For the hexagon (the polygon
- Page 92 and 93:
Creating Polygon Art Using Nested L
- Page 94 and 95:
Endless Graphics In Listing 5-10 yo
- Page 96:
Write a program to have the turtle
- Page 99 and 100:
Talking to the Computer Until now,
- Page 101 and 102:
Figure 6-2: The text window waiting
- Page 103 and 104:
4 C = (5 / 9) * (F - 32) 5 C = Math
- Page 105 and 106:
9 noun = TextWindow.Read() 10 11 Te
- Page 108 and 109:
7 Empowering Programs with Math If
- Page 110 and 111:
Here’s a sample run of our progra
- Page 112 and 113:
Round() -4 -3.5 -3 0 3 3.5 4 Round(
- Page 114 and 115:
This code snippet shows you some ex
- Page 116 and 117:
Let’s walk through this program l
- Page 118 and 119:
Trigonometric Methods Trigonometric
- Page 120:
Programming Challenges If you get s
- Page 123 and 124:
Small Basic uses a few different wa
- Page 125 and 126:
You can test all sorts of condition
- Page 127 and 128:
Small Basic first finds the value o
- Page 129 and 130:
Your mom’s instructions assume th
- Page 131 and 132:
But wait, your mom just realized th
- Page 133 and 134:
This code asks the user to enter a
- Page 136 and 137:
9 Using Decisions to Make Games Som
- Page 138 and 139:
Condition 1 True Statement set 1 If
- Page 140 and 141:
This change to the program means th
- Page 142 and 143:
Door 1 Door 2 Door 3 Figure 9-6: Pe
- Page 144 and 145:
Listing 9-4 shows an example of usi
- Page 146 and 147:
Think of the Shapes object as a “
- Page 148 and 149:
Background image (Grid.png) Star.pn
- Page 150 and 151:
In Figure 9-8, you see that the gri
- Page 152 and 153:
This code asks the player to enter
- Page 154 and 155:
10 Solving Problems with Subroutine
- Page 156 and 157:
Gulliver later learned that 1 glum-
- Page 158 and 159:
TRY IT OUT 10-1 When Gulliver asked
- Page 160 and 161:
variables that belong to the main p
- Page 162 and 163:
4 TextWindow.WriteLine("Your turn.
- Page 164 and 165:
1 step away). If the arrow hits the
- Page 166 and 167:
Then you set the graphics window’
- Page 168 and 169:
24 Shapes.SetText(msgText, "") 25 T
- Page 170 and 171:
Step 8: Shoot Arrows with ShootArro
- Page 172 and 173:
Lines 3-7 animate the dragon’s fi
- Page 174 and 175:
11 Event-Driven Programming So far,
- Page 176 and 177:
GraphicsWindow Events Let’s start
- Page 178 and 179:
4 5 Sub OnKeyDown 6 GraphicsWindow.
- Page 180 and 181:
13 Else 14 GraphicsWindow.DrawText(
- Page 182 and 183:
Useful Tips Before moving on, we’
- Page 184 and 185:
21 GraphicsWindow.BrushColor = "Red
- Page 186 and 187:
4 XG = Math.GetRandomNumber(8) - 1
- Page 188:
Programming Challenges If you get s
- Page 191 and 192:
Today, most programs use a graphica
- Page 193 and 194:
located at (100, 100). By default,
- Page 195 and 196:
9 GraphicsWindow.MouseMove = OnMous
- Page 197 and 198:
Let’s look at the computations. Y
- Page 199 and 200:
You start by loading the two backgr
- Page 201 and 202:
(line 8). If the total resistance i
- Page 203 and 204:
TRY IT OUT 12-4 Write a program to
- Page 206 and 207:
13 Repeating For Loops Have you eve
- Page 208 and 209:
Each For loop starts with the keywo
- Page 210 and 211:
The program uses a variable named s
- Page 212 and 213:
TRY IT OUT 13-5 What does the follo
- Page 214 and 215:
Nested Loops The statements in the
- Page 216 and 217:
Figure 13-7: The output of Stamp.sb
- Page 218:
2. Although the pizza in the previo
- Page 221 and 222:
In this chapter, you’ll learn how
- Page 223 and 224:
Note Although it’s not required b
- Page 225 and 226:
asks the user for the correct answe
- Page 227 and 228:
to become a value other than 0 (thi
- Page 229 and 230:
Step 4: Announce the Winner The las
- Page 232 and 233:
15 Grouping Data in One-Dimensional
- Page 234 and 235:
One way to think of an array is as
- Page 236 and 237:
The string initializer lets you fil
- Page 238 and 239:
TextWindow.WriteLine("Enter 5 numbe
- Page 240 and 241:
how much money was rescued from eac
- Page 242 and 243:
To create this program, we’ll use
- Page 244 and 245:
The apples fall from the trees. Usi
- Page 246 and 247:
The subroutine uses a For loop to c
- Page 248 and 249:
9 If ((xdiff < 20) And (ydiff < 20)
- Page 250:
4. Open the file USMapQuiz_Incomple
- Page 253 and 254:
Associative Arrays In the previous
- Page 255 and 256:
The expression If("ernie" = "Ernie"
- Page 257 and 258:
Here’s the output from a sample r
- Page 259 and 260:
The ContainsIndex() method takes tw
- Page 261 and 262:
Figure 16-1 shows the user interfac
- Page 263 and 264:
1 Sub OnButtonClicked 2 GraphicsWin
- Page 266 and 267:
17 Expanding to Higher-Dimension Ar
- Page 268 and 269:
1 ' Random2DArray.sb 2 For r = 1 To
- Page 270 and 271:
Animated Squares Let’s write a pr
- Page 272 and 273:
12 TextWindow.Write("Enter student
- Page 274 and 275:
(line 8). Line 9 displays Scott's M
- Page 276 and 277:
You start by initializing the sum v
- Page 278 and 279:
4 For col = 1 To 4 ' For each colum
- Page 280 and 281:
note If you run into any problems,
- Page 282 and 283:
First, you set all the elements of
- Page 284 and 285:
11 If ((rowP < 1) Or (rowP > 10) Or
- Page 286:
Open the file Okla.sb from this cha
- Page 289 and 290: (both uppercase and lowercase), dig
- Page 291 and 292: Taking Strings Apart: Substrings Ju
- Page 293 and 294: two arguments: the source string th
- Page 295 and 296: Here’s an output example: Who's y
- Page 297 and 298: More on Code Points The Unicode cod
- Page 299 and 300: Line 7 gets the Nth character of th
- Page 301 and 302: Igpay Atinlay Let’s teach the com
- Page 303 and 304: 17 TextWindow.WriteLine("Good Job!"
- Page 305 and 306: 9 pos = Math.GetRandomNumber(len) '
- Page 307 and 308: When you continue with the second a
- Page 309 and 310: TRY IT OUT 18-10 Use the techniques
- Page 312 and 313: 19 Receiving File Input and Output
- Page 314 and 315: and their meanings. File extensions
- Page 316 and 317: program’s folder (right-click the
- Page 318 and 319: in the file would run together in o
- Page 320 and 321: Let’s experiment with the first p
- Page 322 and 323: line number. As with the WriteLine(
- Page 324 and 325: WARNING If the destination path poi
- Page 326 and 327: 6 For N = 1 To count ' Displays the
- Page 328 and 329: wizard asks the user to perform. Th
- Page 330 and 331: Figure 19-8 shows a sample run of t
- Page 332 and 333: Where to Go from Here So you’ve m
- Page 334 and 335: Index Numbers and Symbols 3DArrayDe
- Page 336 and 337: squares, 31-32 star, 65-66 triangle
- Page 340 and 341: parts of, 14-16 publishing, 5-6 run
- Page 342 and 343: NewGame() subroutine, 255-256 OnBut
- Page 344: ages 10 and up “Welcome to the ma