TextWindow.Write("Hello ") + ", ") TextWindow.Write(name2 + ", ") TextWindow.Write(name3 + ", ") TextWindow.Write(name4 + ", ") When you run this you’ll get the following result: Figure - Not arrays Clearly there must be a better way to write such a simple program, right? Especially since the computer is really good at doing repetitive tasks, why should we bother with writing the same code over and over for every new user? The trick here is to store and retrieve more than one user’s name using the same variable. If we can do that then we can use a For loop we learned in earlier chapters. This is where arrays come to our help. What is an array? An array is a special kind of variable which can hold more than one value at a time. Basically, what it means is that instead of having to create name1, name2, name3, name4 and name5 in order to store five user names, we could just use name to store all five users’ name. The way we store multiple values is by use of this thing called “index.” For example, name[1], name[2], name[3], name[4] and name[5] can all store a value each. The numbers 1, 2, 3, 4 and 5 are called indices for the array. Even though the name[1], name[2], name[3], name[4] and name[5] all look like they are different variables, they’re in reality all just one variable. And what’s the advantage of this, you may ask. The best part of storing values in an array is that you can specify the index using another variable – which allows us to easily access arrays inside loops. Now, let’s look at how we can put our new knowledge to use by rewriting our previous program with arrays. For i = 1 To 5 TextWindow.Write("User" + i + ", enter name: ") name[i] = TextWindow.Read() EndFor TextWindow.Write("Hello ") For i = 1 To 5 TextWindow.Write(name[i] + ", ") EndFor
Appendix B Colors Here’s a list of colors supported by Small Basic, categorized by their base hue. Red Colors IndianRed #CD5C5C LightCoral #F08080 Salmon #FA8072 DarkSalmon #E9967A LightSalmon #FFA07A Crimson #DC143C Red #FF0000 FireBrick #B22222 DarkRed #8B0000 Pink Colors Pink #FFC0CB LightPink #FFB6C1 HotPink #FF69B4 DeepPink #FF1493 MediumVioletRed #C71585 PaleVioletRed #DB7093 Orange Colors LightSalmon #FFA07A Coral #FF7F50 Tomato #FF6347 OrangeRed #FF4500 DarkOrange #FF8C00 Orange #FFA500 Yellow Colors Gold #FFD700 Yellow #FFFF00 LightYellow #FFFFE0 LemonChiffon #FFFACD LightGoldenrodYellow #FAFAD2 PapayaWhip #FFEFD5 Moccasin #FFE4B5 PeachPuff #FFDAB9 PaleGoldenrod #EEE8AA
#F0E68C DarkKhaki #BDB76B Purple Colors Lavender #E6E6FA Thistle #D8BFD8 Plum #DDA0DD Violet #EE82EE Orchid #DA70D6 Fuchsia #FF00FF Magenta #FF00FF MediumOrchid #BA55D3 MediumPurple #9370DB BlueViolet #8A2BE2 DarkViolet #9400D3 DarkOrchid #9932CC DarkMagenta #8B008B Purple #800080 Indigo #4B0082 SlateBlue #6A5ACD DarkSlateBlue #483D8B MediumSlateBlue #7B68EE Green Colors GreenYellow #ADFF2F Chartreuse #7FFF00 LawnGreen #7CFC00 Lime #00FF00 LimeGreen #32CD32 PaleGreen #98FB98 LightGreen #90EE90 MediumSpringGreen #00FA9A SpringGreen #00FF7F MediumSeaGreen #3CB371 SeaGreen #2E8B57 ForestGreen #228B22 #008000 DarkGreen #006400 YellowGreen #9ACD32 OliveDrab #6B8E23 Olive #808000 DarkOliveGreen #556B2F MediumAquamarine #66CDAA DarkSeaGreen #8FBC8F LightSeaGreen #20B2AA DarkCyan #008B8B Teal #008080 Blue Colors Aqua #00FFFF Cyan #00FFFF LightCyan #E0FFFF PaleTurquoise #AFEEEE Aquamarine #7FFFD4 Turquoise #40E0D0 MediumTurquoise #48D1CC DarkTurquoise #00CED1 CadetBlue #5F9EA0 SteelBlue #4682B4 LightSteelBlue #B0C4DE PowderBlue #B0E0E6 LightBlue #ADD8E6 SkyBlue #87CEEB LightSkyBlue #87CEFA
DeepSkyBlue #00BFFF DodgerBlue #1E90FF CornflowerBlue #6495ED MediumSlateBlue #7B68EE RoyalBlue #4169E1 Blue #0000FF MediumBlue #0000CD DarkBlue #00008B Navy #000080 MidnightBlue #191970 Brown Colors Cornsilk #FFF8DC BlanchedAlmond #FFEBCD Bisque #FFE4C4 NavajoWhite #FFDEAD Wheat #F5DEB3 BurlyWood #DEB887 Tan #D2B48C RosyBrown #BC8F8F SandyBrown #F4A460 Goldenrod #DAA520 DarkGoldenrod #B8860B Peru #CD853F Chocolate #D2691E SaddleBrown #8B4513 Sienna #A0522D Brown #A52A2A Maroon #800000 White Colors White #FFFFFF Snow #FFFAFA Honeydew #F0FFF0 MintCream #F5FFFA Azure #F0FFFF AliceBlue #F0F8FF GhostWhite #F8F8FF WhiteSmoke #F5F5F5 Seashell #FFF5EE Beige #F5F5DC OldLace #FDF5E6 FloralWhite #FFFAF0 #FFFFF0 AntiqueWhite #FAEBD7 #FAF0E6 LavenderBlush #FFF0F5 MistyRose #FFE4E1 Gray Colors Gainsboro #DCDCDC LightGray #D3D3D3 Silver #C0C0C0 DarkGray #A9A9A9 Gray #808080 DimGray #696969 LightSlateGray #778899 SlateGray #708090 DarkSlateGray #2F4F4F Black #000000