Download Beginning Programming for Dummies PDF

TitleBeginning Programming for Dummies
TagsProgramming For Dummies
File Size7.7 MB
Total Pages433
Table of Contents
                            Beginning Programming FOR Dummies 3RD EDITION
About the Author
Author’s Acknowledgments
Contents at a Glance
Table of Contents
Who Should Buy This Book
How This Book Is Organized
	Who Should Buy This Book
	How This Book Is Organized
		Part I: Programming a Computer
		Part II: Learning Programming with Liberty BASIC
		Part III: Advanced Programming with Liberty BASIC
		Part V: Algorithms: Telling the Computer What to Do
		Part V: Algorithms: Telling the Computer What to Do
		Part VI: Internet Programming
		Part VII: The Part of Tens
	How to Use This Book
		Foolish assumptions
		Icons used in this book
Part I Programming a Computer
	Chapter 1: Learning Computer Programming for the First Time
		Why Learn Computer Programming?
		How Does a Computer Program Work?
			Programming is problem- solving
			Programming isn't difficult; it's just time-consuming
		What Do I Need to Know to Program a Computer?
	Chapter 2: All about Programming Languages
		Why So Many Different Programming Languages?
			The joy of assembly language
			C: The portable assembler
			High-level programming languages
			Rapid Application Development ( RAD) programming languages
			Database programming languages
			Scripting programming languages
			Web- page programming languages
		So What's the Best Programming Language to Learn?
	Chapter 3: How to Write a Program
		Before You Write Your Program
			The program’s users
			The target computer
			Your own programming skill
		The Technical Details of Writing a Program
			Choosing a programming language
			Defining how the program should work
		The Life Cycle of a Typical Program
			The development cycle
			The maintenance cycle
			The upgrade cycle
	Chapter 4: The Tools of a Computer Programmer
		Writing Programs in an Editor
		Using a Compiler or an Interpreter
			P-code: A combination compiler and interpreter
			So what do I use?
		Squashing Bugs with a Debugger
		Writing a Help File
		Creating an Installation Program
Part II: Learning Programming with Liberty BASIC
	Chapter 5: Getting Your Hands on a Real Language:Liberty BASIC
		Why Learn Liberty BASIC?
			Liberty BASIC is ( almost) free
			Liberty BASIC is easy
			Liberty BASIC runs on Windows
			You can start using Liberty BASIC today
		Installing Liberty BASIC
		Loading Liberty BASIC
		Your First Liberty BASIC Program
			Running a Liberty BASIC program
			Loading or starting a Liberty BASIC program
			Saving a Liberty BASIC program
		Using Keystroke Commands in Liberty BASIC
		Getting Help Using Liberty BASIC
		Exiting Liberty BASIC
	Chapter 6: Handling Input and Output
		Inputting and Outputting Data: The Old- Fashioned Way
		Inputting and Outputting Data:The Modern Way
			Getting input
			Displaying output
		Sending Data to the Printer
	Chapter 7: Variables, Constants,and Comments
		Storing Data in Variables
			Creating a variable
			Assigning a value to a variable
			Declaring your variables
		Using Constants
		Commenting Your Code
	Chapter 8:Crunching Numbers and Playing with Strings
		Adding, Subtracting, Dividing,and Multiplying
			Using variables
			Working with precedence
			Using parentheses
		Using Liberty BASIC's Built-In Math Functions
		Manipulating Strings
			Declaring variables as strings
			Smashing strings together
		Playing with Liberty BASIC's String Functions
			Counting the length of a string
			Playing with UPPERCASE and lowercase
			Trimming the front and back of a string
			Inserting spaces
			Yanking characters out of a string
			Looking for a string inside another string
			Converting strings into numbers (and vice versa)
	Chapter 9: Making Decisions with Control Statements
		Using Boolean Expressions
			Using variables in Boolean expressions
			Using Boolean operators
		Exploring IF THEN Statements
			IF THEN ELSE statements
		Working with SELECT CASE Statements
			Checking a range of values
			Checking a relational operator
	Chapter 10: Repeating Yourself with Loops
		Using the WHILE- WEND Loop
			Exiting a WHILE- WEND loop prematurely
			Endless loops # 1: Failing to modify the
			Boolean expression inside the loop
			Endless loops # 2: Failing to initialize a
			Boolean expression outside the loop
		Looping a Fixed Number of Times
			Counting with different numbers
			Counting in increments
			Exiting a FOR- NEXT loop prematurely
Part III: Advanced Programming
	Chapter 15: Debugging Programs
		Anatomy of a Computer Bug
		Syntax Errors
		Run- Time Errors
		Fun with Logic Errors
			Stepping line by line
			Tracing through your program
	Chapter 14: Creating a User Interface
		Designing a Window
			Creating a new window
			Defining the size and location of a window
			Adding color to a window
		Putting Pull- Down Menus in a Window
		Making Pop- Up Menus
		Putting Controls in a Window
			Creating a command button
			Displaying text
			Creating a check box
			Creating a radio button
			Creating text boxes
			Creating list boxes
			Creating combo boxes
			Creating group boxes
	Chapter 13: Saving and Retrieving Stuff in Files
		Storing Stuff in Text Files
			Creating a new text file
			Putting stuff in a text file
			Adding new stuff to an existing text file
			Retrieving data from a text file
		Storing Stuff in Random- Access Files
			Creating a new random- access file
			Saving data into a random- access file
			Retrieving data from a random- access file
		Saving and Retrieving Data in a Binary File
			Creating a new binary file
			Saving stuff in a binary file
			Changing stuff in a binary file
			Retrieving stuff from a binary file
	Chapter 12: Drawing Pictures and Making Noise
		Creating a Graphics Control
		Using Turtle Graphics
			Defining line thickness
			Defining line colors
		Drawing Circles
		Drawing Boxes
		Displaying Text
		Making Sounds
			Making a beeping noise
			Playing WAV files
	Chapter 11: Writing Large Programs by Using Subprograms
		Passing Data by Value or by Reference
		Using Functions
			Defining a function
			Passing data to a function
			Calling a function
			Exiting prematurely from a function
		Using Subroutines
			Defining a subroutine
			Passing data to a subroutine
			Calling a subroutine
			Exiting prematurely from a subroutine
		Writing Modular Programs
		Introducing Structured Programming
			Sequential instructions
			Branching instructions
			Looping instructions
			Putting structured programming into practice
		Breaking the Bad Programming Habits of the Past
Part IV: Dealing with Data Structures
	Chapter 19: Playing with Object-Oriented Programming
		The Problem with Software
		Ways to Make Programming Easier
		Breaking Programs into Objects
			How to use objects
			How to create an object
			Writing an object's methods
			Creating an object
		Choosing an Object- Oriented Language
	Chapter 18: Linked Lists and Pointers
		Starting with a Pointer
			Defining the parts of a linked list
			Creating a linked list
			Managing a linked list
		Making Data Structures with Linked Lists
			Double- linked lists
			Circular- linked lists
	Chapter 17: Lumping Related Data in Records
		Creating a Record
		Manipulating Data in Records
			Storing data in a record
			Retrieving data from a record
		Using Records with Arrays
	Chapter 16: Storing Stuff in Arrays
		Making an Array
		Storing (and Retrieving) Data in an Array
		Making a Multidimensional Array
		Creating Dynamic Arrays
Part V: Algorithms: Telling the Computer What to Do
	Chapter 20: Sorting
		Insertion Sort
		Bubble Sort
		Shell Sort
		Sorting Algorithms
	Chapter 21: Searching
		Searching Sequentially
		Performing a Binary Search
			Searching by using a hash function
			Dealing with collisions
		Picking a Searching Algorithm
	Chapter 22: Optimizing Your Code
		Choosing the Right Data Structure
		Choosing the Right Algorithm
		Fine- Tuning the Source Code
			Put the condition most likely to be false first
			Put the condition most likely to be true first
			Don't run a FOR-NEXT loop needlessly
			Clean out your loops
			Use the correct data types
			Use built- in commands whenever possible
		Using a Faster Language
		Optimizing Your Compiler
Part VII: The Part of Tens
	Chapter 26: Ten Cool Programming Careers
		Programming Computer Games
		Creating Computer Animation
		Making (And Breaking) Encryption
		Internet Programming
		Fighting Computer Viruses and Worms
		Hacking for Hire
		Participating in an Open-Source Project
		Niche-Market Programming
		Teaching Others about Computers
		Selling Your Own Software
	Chapter 27: Ten Additional Programming Resources
		Trying Commercial Compilers
			Windows programming
			Macintosh and Palm OS programming
			Linux programming
		Testing the Shareware and
			BASIC compilers
			C/C++ and Java compilers
			Pascal compilers
			Oddball language compilers
		Using a Proprietary Language
		Shopping by Mail Order
		Getting Your Hands on Source Code
		Joining a Local User Group
		Frequenting Usenet Newsgroups
		Playing Core War
		Programming a Battling Robot
		Toying with Lego Mindstorms
Appendix: About the CD
Bonus Chapter: Programming in Python
End-User License Agreement
Document Text Contents
Page 2

by Wallace Wang





549979 FM.qxd 11/6/03 1:46 PM Page i

Page 216

10. The tenth line marks the end of the program.

11. The eleventh line identifies the label [asOpen]. After the user chooses
the Open command from the File menu, the computer jumps to this line
to look for further instructions to follow.

12. The twelfth and thirteenth lines tell the computer, “Display a Notice dialog
box with the message, Open command chosen. Then wait for the user to
do something else.”

13. The fourteenth line identifies the label [asPrint]. After the user chooses
the Print command from the File menu, the computer jumps to this line
to look for further instructions to follow.

14. The fifteenth and sixteenth lines tell the computer, “Display a Notice
dialog box with the message, Print command chosen. Then wait for
the user to do something else.”

To define additional menus for a window, as shown in Figure 14-2, just use
multiple MENU commands, as in the following example:

MENU #1, “&File”, “&Open”, [asOpen], “&Print”, [asPrint],

“E&xit”, [quit]
MENU #1, “&Help”, “&Contents”, [asContents], “&About”,

OPEN “Menu Example” FOR Window AS #1
PRINT #1, “trapclose [quit]”

CONFIRM “Are you sure that you want to quit?”; quit$
IF quit$ = “no” THEN WAIT

NOTICE “Open command chosen”

NOTICE “Print command chosen”

NOTICE “Contents command chosen”

NOTICE “About command chosen”

197Chapter 14: Creating a User Interface

19 549979 Ch14.qxd 11/4/03 12:19 PM Page 197

Page 217

Each time that you create additional menu commands, you need to create
instructions (which a [label] identifies) for the computer to follow when-
ever the user chooses those commands.

Making Pop-Up Menus
In addition to pull-down menus, many programs also offer pop-up menus that
appear next to the mouse pointer when you right-click the mouse. To create a
pop-up menu in Liberty BASIC, you need to use the POPUPMENU command, as

POPUPMENU “command1”, [label1], “command2”, [label2]

To make the POPUPMENU easier to understand, place each command and label
on a separate line and use the underscore character (_) at the end of each line.
The underscore character tells Liberty BASIC that additional instructions
appear on the following line. You can use the underscore character to divide
long lines of commands into shorter, separate lines, such as you see in the
following example:

“command1”, [label1], _
“command2”, [label2], _
“command3”, [label3]

Figure 14-2:

can create


198 Part III: Advanced Programming with Liberty BASIC

19 549979 Ch14.qxd 11/4/03 12:19 PM Page 198

Page 432

Wiley Publishing, Inc.
End-User License Agreement

READ THIS. You should carefully read these terms and conditions before opening the software
packet(s) included with this book “Book”. This is a license agreement “Agreement” between you
and Wiley Publishing, Inc.,“WPI”. By opening the accompanying software packet(s), you acknowl-
edge that you have read and accept the following terms and conditions. If you do not agree and do
not want to be bound by such terms and conditions, promptly return the Book and the unopened
software packet(s) to the place you obtained them for a full refund.

1. License Grant. WPI grants to you (either an individual or entity) a nonexclusive license to
use one copy of the enclosed software program(s) (collectively, the “Software” solely for your
own personal or business purposes on a single computer (whether a standard computer or a
workstation component of a multi-user network). The Software is in use on a computer when
it is loaded into temporary memory (RAM) or installed into permanent memory (hard disk,
CD-ROM, or other storage device). WPI reserves all rights not expressly granted herein.

2. Ownership. WPI is the owner of all right, title, and interest, including copyright, in and to the
compilation of the Software recorded on the disk(s) or CD-ROM “Software Media”. Copyright
to the individual programs recorded on the Software Media is owned by the author or other
authorized copyright owner of each program. Ownership of the Software and all proprietary
rights relating thereto remain with WPI and its licensers.

3. Restrictions On Use and Transfer.

(a) You may only (i) make one copy of the Software for backup or archival purposes, or (ii)
transfer the Software to a single hard disk, provided that you keep the original for backup
or archival purposes. You may not (i) rent or lease the Software, (ii) copy or reproduce
the Software through a LAN or other network system or through any computer subscriber
system or bulletin- board system, or (iii) modify, adapt, or create derivative works based
on the Software.

(b) You may not reverse engineer, decompile, or disassemble the Software. You may transfer
the Software and user documentation on a permanent basis, provided that the transferee
agrees to accept the terms and conditions of this Agreement and you retain no copies. If
the Software is an update or has been updated, any transfer must include the most recent
update and all prior versions.

4. Restrictions on Use of Individual Programs. You must follow the individual requirements and
restrictions detailed for each individual program in the About the CD-ROM appendix of this
Book. These limitations are also contained in the individual license agreements recorded on
the Software Media. These limitations may include a requirement that after using the program
for a specified period of time, the user must pay a registration fee or discontinue use. By open-
ing the Software packet(s), you will be agreeing to abide by the licenses and restrictions for
these individual programs that are detailed in the About the CD-ROM appendix and on the
Software Media. None of the material on this Software Media or listed in this Book may ever
be redistributed, in original or modified form, for commercial purposes.

39 549979 EULA.qxd 11/4/03 12:22 PM Page 413

Page 433

5. Limited Warranty.

(a) WPI warrants that the Software and Software Media are free from defects in materials and
workmanship under normal use for a period of sixty (60) days from the date of purchase
of this Book. If WPI receives notification within the warranty period of defects in materials
or workmanship, WPI will replace the defective Software Media.


(c) This limited warranty gives you specific legal rights, and you may have other rights that
vary from jurisdiction to jurisdiction.

6. Remedies.

(a) WPI’s entire liability and your exclusive remedy for defects in materials and workman-
ship shall be limited to replacement of the Software Media, which may be returned to
WPI with a copy of your receipt at the following address: Software Media Fulfillment
Department, Attn.: Beginning Programming For Dummies, 3rd Edition, Wiley Publishing,
Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, or call 1-800-762-2974. Please allow
four to six weeks for delivery. This Limited Warranty is void if failure of the Software Media
has resulted from accident, abuse, or misapplication. Any replacement Software Media
will be warranted for the remainder of the original warranty period or thirty (30) days,
whichever is longer.

(b) In no event shall WPI or the author be liable for any damages whatsoever (including
without limitation damages for loss of business profits, business interruption, loss of
business information, or any other pecuniary loss) arising from the use of or inability to
use the Book or the Software, even if WPI has been advised of the possibility of such

(c) Because some jurisdictions do not allow the exclusion or limitation of liability for conse-
quential or incidental damages, the above limitation or exclusion may not apply to you.

7. U.S. Government Restricted Rights. Use, duplication, or disclosure of the Software for or on
behalf of the United States of America, its agencies and/or instrumentalities “U.S. Government”
is subject to restrictions as stated in paragraph (c)(1)(ii) of the Rights in Technical Data and
Computer Software clause of DFARS 252.227-7013, or subparagraphs (c) (1) and (2) of the
Commercial Computer Software - Restricted Rights clause at FAR 52.227-19, and in similar
clauses in the NASA FAR supplement, as applicable.

8. General. This Agreement constitutes the entire understanding of the parties and revokes
and supersedes all prior agreements, oral or written, between them and may not be modified
or amended except in a writing signed by both parties hereto that specifically refers to this
Agreement. This Agreement shall take precedence over any other documents that may be in
conflict herewith. If any one or more provisions contained in this Agreement are held by any
court or tribunal to be invalid, illegal, or otherwise unenforceable, each and every other pro-
vision shall remain in full force and effect.

39 549979 EULA.qxd 11/4/03 12:22 PM Page 414

Similer Documents