Programming for the Absolute Beginner
Format: PDF / Kindle (mobi) / ePub
Want to learn computer programming but aren't sure where to start? Programming for the Absolute Beginner provides a gentle learning curve in programming for anyone who wants to develop fundamental programming skills and create computer programs. The primary focus is on teaching the reader how to program using a free implementation of BASIC called Just BASIC. As such, the book focuses on developing programs that run on Microsoft Windows, but also presents programming principles that apply to different environments, including other operating systems and the Internet. Additionally, the book provides a solid foundation for advancing to different programming languages as you gain confidence in your newly acquired programming abilities. As part of the for the absolute beginner series, Programming for the Absolute Beginner teaches all the concepts through the creation of simple computer games, making the learning process much more fun and enjoyable.
the game, the player asks the game a series of questions that must be worded in such a way as to work with yes/no-styled answers, as demonstrated in Figure 3.4. In response to each question, the game displays a randomly generated answer of YES, NO, or MAYBE, as demonstrated in Figure 3.5. 03 ProgABS2E ch03 2/23/15 8:41 PM Page 73 Chapter 3 • Creating Graphical User Interfaces Figure 3.2 The player is prompted to ask a question. © 2016 Cengage Learning® 73 Figure 3.3 An error message is
Other Data Storage Options Although Just BASIC support for data manipulation is limited to variables and one- or twodimensional arrays, other programming languages offer additional ways of storing and retrieving data. For example, Perl allows programmers to define hashes, sometimes referred to as associated arrays, in which data is stored in key-value pairs, and each data element stored in a hash is assigned a unique key. You can then retrieve data from the hash by referencing its associated key.
understanding of how the val() function works, take a look at the following example: expression apples$ = “25” oranges = 5 apples = val(apples$) fruit = apples + oranges print “You have “; fruit; “ pieces of fruit.” Here, a string variable named apples$ has been assigned a string value of 25 and a numeric variable named oranges has been assigned a value of 5. Next, the val() function is used to convert the string value assigned to apples$ to its numeric equivalent. The numeric values of apples
Trim$(). Removes leading blank spaces from the beginning and the end of a string Upper$(). Returns a string that has been converted to all uppercase To see an example of a number of these string manipulation functions in action, take a look at the following example: storyText$ = “ Once upon a time…” storyText$ = trim$(storyText$) ‘Returns “Once upon a time…” 04 ProgABS2E ch04 2/23/15 8:37 PM Page 144 144 Programming for the Absolute Beginner, Second Edition storyText$ = upper$(storyText$)
into it listbox #play.listbox, wishes$(), doubleClick, 20, 280, 300, 80 ‘Define the format of button controls displayed on the window button #play.button1 “ Hint “, GetHint, UL, 220, 380 button #play.button2 “ Quit “, ClosePlay, UL, 305, 380 04 ProgABS2E ch04 2/23/15 8:37 PM Page 153 Chapter 4 • Working with Variables and Arrays 153 ‘Add a texteditor control to the #play window (used to display Tabethia’s ‘responses) texteditor #play.texteditor, 330, 280, 240, 80 ‘Open the window with