- •About the Author
- •Dedication
- •Author’s Acknowledgments
- •Contents at a Glance
- •Table of Contents
- •Introduction
- •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 VI: Internet Programming
- •Part VII: The Part of Tens
- •How to Use This Book
- •Foolish assumptions
- •Icons used in this book
- •Why Learn Computer Programming?
- •How Does a Computer Program Work?
- •What Do I Need to Know to Program a Computer?
- •The joy of assembly language
- •C: The portable assembler
- •High-level programming languages
- •Database programming languages
- •Scripting programming languages
- •The program’s users
- •The target computer
- •Prototyping
- •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
- •Writing Programs in an Editor
- •Using a Compiler or an Interpreter
- •Compilers
- •Interpreters
- •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
- •Why Learn Liberty BASIC?
- •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
- •Saving a Liberty BASIC program
- •Getting Help Using Liberty BASIC
- •Exiting Liberty BASIC
- •Getting input
- •Displaying output
- •Sending Data to the Printer
- •Storing Data in Variables
- •Creating a variable
- •Assigning a value to a variable
- •Declaring your variables
- •Using Constants
- •Commenting Your Code
- •Using variables
- •Working with precedence
- •Using parentheses
- •Manipulating Strings
- •Declaring variables as strings
- •Smashing strings together
- •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
- •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
- •Boolean expression inside the loop
- •Looping a Fixed Number of Times
- •Counting with different numbers
- •Counting in increments
- •Anatomy of a Computer Bug
- •Syntax Errors
- •Fun with Logic Errors
- •Stepping line by line
- •Tracing through your program
- •Designing a Window
- •Creating a new window
- •Defining the size and location of a window
- •Adding color to a window
- •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
- •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
- •Creating a new binary file
- •Saving stuff in a binary file
- •Changing stuff in a binary file
- •Retrieving stuff from a binary file
- •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
- •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
- •The Problem with Software
- •Ways to Make Programming Easier
- •Breaking Programs into Objects
- •How to use objects
- •How to create an object
- •Creating an object
- •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
- •Stacks
- •Queues
- •Trees
- •Graphs
- •Creating a Record
- •Manipulating Data in Records
- •Storing data in a record
- •Retrieving data from a record
- •Using Records with Arrays
- •Making an Array
- •Making a Multidimensional Array
- •Creating Dynamic Arrays
- •Insertion Sort
- •Bubble Sort
- •Shell Sort
- •Quicksort
- •Sorting Algorithms
- •Searching Sequentially
- •Performing a Binary Search
- •Hashing
- •Searching by using a hash function
- •Dealing with collisions
- •Picking a Searching Algorithm
- •Choosing the Right Data Structure
- •Choosing the Right Algorithm
- •Put the condition most likely to be false first
- •Put the condition most likely to be true first
- •Clean out your loops
- •Use the correct data types
- •Using a Faster Language
- •Optimizing Your Compiler
- •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
- •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
- •Using a Proprietary Language
- •HyperCard
- •Revolution
- •PowerBuilder
- •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
- •Index
- •End-User License Agreement
376 Part VII: The Part of Tens
Programming a handheld computer
Microsoft created a stripped-down version of Windows known as Windows CE for use in handheld and palm-size computers (often known as PocketPC computers). Unfortunately, programs that you write for Windows 98/Me/NT/2000/XP can’t run on Windows CE. So if you want to write programs for Windows CE, you must use a special Windows CE compiler. Microsoft developed Windows CE, so naturally Microsoft offers Windows CE programming toolkits so that you can write programs for Windows CE/PocketPC computers by using either Visual C++ or Visual Basic.
Two other programming languages for writing Windows CE/PocketPC programs include Pocket C (at www.orbworks.com) and NSBASIC (at
www.nsbasic.com). Pocket C uses a strippeddown version of the C programming language, and NSBASIC uses a stripped-down version of the BASIC programming language. Pocket C and NSBASIC aren’t quite as powerful as Visual C++ and Visual Basic, but they still enable you to create commercial-quality programs for a Windows CE/PocketPC computer.
Both Pocket C and NSBASIC also come in versions that run under the Palm OS, so you can also write programs for the Palm handheld computer. Because the Palm OS and Windows CE/Pocket PC are drastically different computers, you can’t run your programs on both the Palm OS and Windows CE/Pocket PC without extensive modification.
Testing the Shareware and
Freeware Compilers
Choosing a programming language can often prove as emotional and subjective as choosing someone to marry. Rather than buy a handful of commercial compilers only to find out that you don’t like any of them or the programming languages that they use, take some time to download a shareware or freeware compiler instead.
As you test shareware or freeware compilers, you can practice using different programming languages such as C++ or Java. If you find a programming language that you like, consider buying the shareware or a similar commercial compiler. For a list of free compilers for a variety of different programming languages, visit the Catalog of Free Compilers and Interpreters Web page at www.idiom.com/free-compilers.
BASIC compilers
For a BASIC compiler that can create MS-DOS and Windows programs, consider PowerBasic (at www.powerbasic.com). For writing MS-DOS programs,
Chapter 27: Ten Additional Programming Resources 377
the company offers their FirstBasic and PowerBasic shareware compilers. For writing Windows programs, try the PowerBasic for Windows compiler.
If you have a Macintosh, you can download the freeware Chipmunk Basic interpreter (not a compiler) from www.nicholson.com/rhn/basic.
One of the more challenging tasks for any programmer is writing 3D computer animated games. Although most programmers use C/C++ to write computer video games, you may want to use your knowledge of BASIC to write your own computer games for Windows by using a special game-creation language known as DarkBASIC (at http://darkbasic.thegamecreators.com).
C/C++ and Java compilers
C and C++ are powerful languages, but they can prove intimidating to many people. Rather than spend lots of money buying a commercial C/C++ compiler, spend some time playing with shareware and freeware C/C++ compilers first.
The most popular C compiler for Linux is the GNU C compiler, so that same compiler was ported to Windows and renamed the Cygwin compiler (at http://sources.redhat.com/cygwin).
For those who want to tackle Java programming, download the free Java software development kit direct from Sun Microsystems (at java.sun.com), the inventors of Java. This bare-bones Java programming tool can help you learn Java.
To help spread the popularity of their C++ and Java compilers, Borland International offers free versions of their C++ Builder and JBuilder compilers. The idea is that if you like using the free versions, you might want to buy their more advanced versions later.
Pascal compilers
Although Pascal has faded in popularity in North America, it’s still popular among a small group of programming die-hards. For a free Pascal compiler for MS-DOS, Windows, and Linux, download Free Pascal from www.freepascal. org. If you always wanted to dig into the guts of a compiler, visit the Bloodshed Software Web site (at www.bloodshed.net), where you can join an ongoing effort to create and develop a Pascal compiler for Windows.
Currently the most well-known Pascal compiler is Delphi, a Visual Basic-like compiler developed by Borland International. To help spread the popularity of Delphi, Borland offers a free version of Delphi (and Kylix, their Linux