Beginning REALbasic
From Novice to Professional
■■■
Jerry Lee Ford, Jr.
Ford634X.book Page i Friday, April 14, 2006 12:29 PM
Beginning REALbasic: From Novice to Professional
Copyright © 2006 by Jerry Lee Ford, Jr.
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means,
electronic or mechanical, including photocopying, recording, or by any information storage or retrieval
system, without the prior written permission of the copyright owner and the publisher.
ISBN-13 (pbk): 978-1-59059-634-0
ISBN-10 (pbk): 1-59059-634-X
Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1
Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence
of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark
owner, with no intention of infringement of the trademark.
Lead Editor: Chris Mills
Technical Reviewer: Allan Kent
Editorial Board: Steve Anglin, Ewan Buckingham, Gary Cornell, Jason Gilmore, Jonathan Gennick,
Jonathan Hassell, James Huddleston, Chris Mills, Matthew Moodie, Dominic Shakeshaft, Jim Sumser,
Keir Thomas, Matt Wade
Project Manager: Richard Dal Porto
Copy Edit Manager: Nicole LeClerc
Copy Editor: Marcia Baker
Assistant Production Director: Kari Brooks-Copony
Production Editor: Lori Bring
Compositor: Pat Christenson
Proofreader: Linda Seifert
Indexer: Broccoli Information Management
Artist: April Milne
Cover Designer: Kurt Krames
Manufacturing Director: Tom Debolski
Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor,
New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail , or
visit .
For information on translations, please contact Apress directly at 2560 Ninth Street, Suite 219, Berkeley, CA
94710. Phone 510-549-5930, fax 510-549-5939, e-mail , or visit .
The information in this book is distributed on an “as is” basis, without warranty. Although every precaution
has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to
any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly
by the information contained in this work.
The source code for this book is available on the accompanying CD. Any corrections to code and errata are
posted for download/viewing at . Just search for the book by title, author, or ISBN,
in the search bar on our homepage.
Ford634X.book Page ii Friday, April 14, 2006 12:29 PM
To Alexander, William, Molly, and Mary.
Ford634X.book Page iii Friday, April 14, 2006 12:29 PM
iv
Contents at a Glance
About the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
About the Technical Reviewer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xx
Acknowledgments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii
PART 1 ■ ■ ■ Introducing REALbasic
■CHAPTER 1 An Introduction to REALbasic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
■CHAPTER 2 Navigating the REALbasic Integrated Development
Environment
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
PART 2 ■ ■ ■ Learning How to
Program with REALbasic
■CHAPTER 3 Creating an Application’s User Interface . . . . . . . . . . . . . . . . . . . . . . . 67
■CHAPTER 4 Working with REALbasic Menus. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
■CHAPTER 5 Storing and Retrieving Application Data . . . . . . . . . . . . . . . . . . . . . . 135
■CHAPTER 6 Making Decisions with Conditional Logic . . . . . . . . . . . . . . . . . . . . . 163
■CHAPTER 7 Iterative Processing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
■CHAPTER 8 Object-Oriented Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
PART 3 ■ ■ ■ Advanced Topics
■CHAPTER 9 Processing Text Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
■CHAPTER 10 Working with Databases. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
■CHAPTER 11 Working with Graphics and Audio . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301
■CHAPTER 12 Debugging REALbasic Applications. . . . . . . . . . . . . . . . . . . . . . . . . . . 323
Ford634X.book Page iv Friday, April 14, 2006 12:29 PM
v
PART 4 ■ ■ ■ Appendixes
■APPENDIX A Migrating Visual Basic Projects to REALbasic . . . . . . . . . . . . . . . . . 347
■APPENDIX B What’s on the CD-ROM?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
■APPENDIX C What’s Next? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353
■INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
Ford634X.book Page v Friday, April 14, 2006 12:29 PM
Ford634X.book Page vi Friday, April 14, 2006 12:29 PM
vii
Contents
About the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
About the Technical Reviewer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xx
Acknowledgments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii
PART 1 ■ ■ ■ Introducing REALbasic
■CHAPTER 1 An Introduction to REALbasic. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Overview of REALbasic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Drag-and-Drop GUI Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Object-Oriented Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
RAD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Cross-Platform Application Development . . . . . . . . . . . . . . . . . . . . . . . 6
What Can REALbasic Do? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
What’s New in REALbasic? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Supported Development Platforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Supported Execution Platforms. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Standard vs. Professional . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
REALbasic 2006 Standard Edition . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
REALbasic 2006 Professional Edition . . . . . . . . . . . . . . . . . . . . . . . . . 12
Downloading REALbasic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
REALbasic vs. Visual Basic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
REALbasic vs. Apple’s XCode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Online REALbasic Support Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Getting Started with Your First REALbasic Application. . . . . . . . . . . . . . . . 19
Hello World! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Compiling Your Application for Macintosh, Windows, and
Linux Execution
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Ford634X.book Page vii Friday, April 14, 2006 12:29 PM
viii
■CONTENTS
■CHAPTER 2 Navigating the REALbasic Integrated Development
Environment
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Starting REALbasic. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
The REALbasic Menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
REALbasic’s Main Toolbar. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Default Main Toolbar Resources. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Configuring REALbasic’s Main Toolbar . . . . . . . . . . . . . . . . . . . . . . . . 38
REALbasic’s Bookmarks Toolbar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Adding New Bookmarks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Editing Your Bookmarks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
REALbasic’s Screen Area . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Tabs Bar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Editor Toolbar. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Screens. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
REALbasic’s Tips Bar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
REALbasic’s Integrated Help Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Accessing REALbasic’s Manuals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Accessing REALbasic Online Resources . . . . . . . . . . . . . . . . . . . . . . . 53
Working with REALbasic’s Electronic Language Reference. . . . . . . 54
Building a Custom Web Browser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
The RBBookFinder Browser. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Designing the User Interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Changing Windows and Control Properties . . . . . . . . . . . . . . . . . . . . 61
Adding a Little REALbasic Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Testing Your Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
PART 2 ■ ■ ■ Learning How to
Program with REALbasic
■CHAPTER 3 Creating an Application’s User Interface. . . . . . . . . . . . . . . . . . 67
Building Application Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Document. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Movable Modal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Modal Window. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Floating Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Plain Box Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Shadowed Box Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Ford634X.book Page viii Friday, April 14, 2006 12:29 PM
■CONTENTS
ix
Rounded Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Global Floating Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Sheet Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Metal Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Drawer Window. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Changing the Default Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Deleting Windows. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Encrypting and Decrypting Windows. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Working with Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Adding Controls to Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Finding Lost Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Modifying Control Properties. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Deleting Controls. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
A REALbasic Control Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
The BevelButton Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
The Canvas Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
The CheckBox Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
The ComboBox Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
The ContextualMenu Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
The DatabaseQuery Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
The DataControl Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
The DisclosureTriangle Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
The EditField Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
The ExcelApplication Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
The GroupBox Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
The HTMLViewer Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
The ImageWell Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
The Line Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
The ListBox Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
The MoviePlayer Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
The NotePlayer Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
The OLEContainer Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
The Oval Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
The PagePanel Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
The Placard Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
The PopupArrow Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
The PopupMenu Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
The PowerPointApplication Control . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
The ProgressBar Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
The ProgressWheel Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Ford634X.book Page ix Friday, April 14, 2006 12:29 PM
x
■CONTENTS
The PushButton Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
The RadioButton Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
The Rb3Dspace Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
The RbScript Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
The Rectangle Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
The RoundRectangle Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
The ScrollBar Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
The Separator Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
The Serial Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
The ServerSocket Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
The Slider Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
The SpotlightQuery Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
The SpriteSurface Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
The StandardToolbarItem Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
The StaticText Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
The TabPanel Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
The TCPSocket Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
The Thread Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
The Timer Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
The ToolbarItem Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
The UDPSocket Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
The UpDownArrows Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
The WordApplication Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Extending REALbasic Functionality by Adding New Controls . . . . . . . . . . 95
Plug-Ins. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
ActiveX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Control Alignment. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Changing Tab Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Building a Desktop Clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Designing the User Interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Changing Window and Control Properties . . . . . . . . . . . . . . . . . . . . 100
Adding a Little REALbasic Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Testing Your Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Ford634X.book Page x Friday, April 14, 2006 12:29 PM
■CONTENTS
xi
■CHAPTER 4 Working with REALbasic Menus. . . . . . . . . . . . . . . . . . . . . . . . . . 103
Working with REALbasic Menu Bars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Examining Menu Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
The Default MenuBar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
Adding a New Menu Bar and Assigning It to a Window . . . . . . . . . 108
Adding Menus, Submenus, and Menu Items. . . . . . . . . . . . . . . . . . . . . . . 109
Adding a New Menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Adding Menu Items. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
Creating a Submenu. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
Previewing Your REALbasic Menus . . . . . . . . . . . . . . . . . . . . . . . . . . 117
Enhancing Menu Systems. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
Using Separator Bars to Organize Menu Items . . . . . . . . . . . . . . . . 119
Setting Up Shortcut Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
Defining Accelerator Keys on Windows and Linux Menus . . . . . . . 121
Using Menu Items to Trigger Command and Code Execution. . . . . . . . . 123
Controlling Access to Menu Items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
Reconfiguring Menu Organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
Moving Menus and Menu Items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
Converting Menu Items to Menus . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
Removing Menu and Menu Items. . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
Customizing the Apple and Macintosh Menus. . . . . . . . . . . . . . . . . . . . . . 128
Creating a StickyPad Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
Designing the User Interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
Supplying Application Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
Testing RBQuickNote . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
■CHAPTER 5 Storing and Retrieving Application Data . . . . . . . . . . . . . . . . . 135
Adding Comments to Your Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Property Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Storing and Retrieving Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
Working with Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
Working with Properties. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
Creating and Working with Variables. . . . . . . . . . . . . . . . . . . . . . . . . 142
Ford634X.book Page xi Friday, April 14, 2006 12:29 PM
xii
■CONTENTS
Converting Between Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Built-In Conversion Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
String Manipulation Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
Storing Data in Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
Loading Data into Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
Retrieving Data from Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Changing the Size of Your Arrays. . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Working with Dictionaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
REALbasic’s Built-In Constants. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
Defining Your Own Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
Reserved Keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
Creating a Starter Desktop Calculator. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
Designing the User Interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
Supplying Application Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
Testing RBCalculator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
■CHAPTER 6 Making Decisions with Conditional Logic. . . . . . . . . . . . . . . . 163
Implementing Conditional Logic. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
Working with the If…Then Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
Single Line If…Then Statements. . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
Multiple Line If Then Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
The If…Then…Else Block. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
The If…Then…ElseIf Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
Nesting If…Then Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
The Select…Case Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
#If…#EndIf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
REALbasic Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
Comparison Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
Mathematical Operators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
Logical Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
Creating a Computer Game. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
Putting Together the Game’s User Interface. . . . . . . . . . . . . . . . . . . 177
Defining Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
Adding a Little Program Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
Testing RB Number Guess. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
Ford634X.book Page xii Friday, April 14, 2006 12:29 PM
■CONTENTS
xiii
■CHAPTER 7 Iterative Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
Processing Data with Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
Do…Loop. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
The While…Wend Loop. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
The For…Next Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
The For…Each Loop. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
Shortcuts for Creating Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
Guarding Against Endless Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
Creating a REALbasic Movie Player. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
Assembling the Application’s User Interface . . . . . . . . . . . . . . . . . . 201
Adding the Program Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
Testing RB Movie Player . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
■CHAPTER 8 Object-Oriented Programming. . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
An Introduction to Object-Oriented Programming. . . . . . . . . . . . . . . . . . . 209
Advantages of Working with REALbasic Classes
and Subclasses
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
Instantiating Objects from Classes and Subclasses . . . . . . . . . . . . 211
Event-Driven Programming. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
Working with Event Handlers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
Working with Menu Handlers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
Working with Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
Adding Modules to REALbasic Applications . . . . . . . . . . . . . . . . . . . 221
Scoping Modules Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
Adding a Property to a Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
Adding a Method to a Module. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
Adding a Constant to a Module. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
Working with Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
Windows Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
Windows Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
Associating New Methods with Windows . . . . . . . . . . . . . . . . . . . . . 226
Building the RB Picture Viewer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
Putting Together the Application’s User Interface . . . . . . . . . . . . . . 232
Adding Custom Constants and Methods. . . . . . . . . . . . . . . . . . . . . . 235
Adding a Little Program Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
Testing RB Picture Viewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
Ford634X.book Page xiii Friday, April 14, 2006 12:29 PM
xiv
■CONTENTS
PART 3 ■ ■ ■ Advanced Topics
■CHAPTER 9 Processing Text Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
Working with Plain and Styled Text Documents . . . . . . . . . . . . . . . . . . . . 243
Defining File Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
Specifying File Types in Your REALbasic Applications . . . . . . . . . . 244
Working with File Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
Accessing Files and Folders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
Specifying File or Folder Location . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
Accessing Special Folders. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
Using Open File and Folder Dialog Windows . . . . . . . . . . . . . . . . . . 247
Verifying Path and File or Folder Existence. . . . . . . . . . . . . . . . . . . . 249
Deleting Files and Folders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
Process Text Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
Reading from Text Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
Writing to Text Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
Working with Styled Text. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
Reading Styled Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
Writing Styled Text to Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
Saving Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
Printing Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
Working with the Page Setup Dialog Window . . . . . . . . . . . . . . . . . 255
Using the Print Dialog Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
Bypassing the Print Dialog Window . . . . . . . . . . . . . . . . . . . . . . . . . . 258
Printing Styled Text. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
Creating a REALbasic Word Processor . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
Putting Together the User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . 259
Defining Supported File Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
Adding Custom Constants and Properties. . . . . . . . . . . . . . . . . . . . . 263
Adding Code That Supports the Menu System. . . . . . . . . . . . . . . . . 263
Adding Code That Supports the Window and Its Controls . . . . . . . 268
Testing RB Word Processor. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272
Ford634X.book Page xiv Friday, April 14, 2006 12:29 PM
■CONTENTS
xv
■CHAPTER 10 Working with Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
REALbasic’s Database Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
Database Plug-Ins. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
Structured Query Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
Creating and Opening REAL SQL Databases . . . . . . . . . . . . . . . . . . . . . . . 275
Creating a New REAL SQL Database from the IDE . . . . . . . . . . . . . 275
Creating a Database in Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276
Connecting to an Existing Database from the IDE. . . . . . . . . . . . . . 276
Connecting to an Existing Database in Code . . . . . . . . . . . . . . . . . . 277
Defining Database Schema. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277
Adding Tables, Columns, and Indexes from the IDE . . . . . . . . . . . . 278
Adding Tables, Columns, Indexes, and Records in Code . . . . . . . . 281
Querying Database Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
Letting REALbasic Generate Your SQL Statements. . . . . . . . . . . . . 283
Advanced SQL Query Statements. . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
Changing Column Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288
Developing Database Front-Ends. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
The DatabaseQuery Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
The DataControl. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
The RB Book Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292
Creating the PersonalBookDB Database . . . . . . . . . . . . . . . . . . . . . . 293
Creating a Utility to Add New Books . . . . . . . . . . . . . . . . . . . . . . . . . 296
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
■CHAPTER 11 Working with Graphics and Audio. . . . . . . . . . . . . . . . . . . . . . . . 301
Adding Sound Effects to REALbasic Applications . . . . . . . . . . . . . . . . . . . 301
Getting the User’s Attention. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
Playing Audio Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
Giving Your Application a Voice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304
Making Music . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305
Working with Graphics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310
REALbasic’s Coordinate System. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310
Displaying Graphic Files as a Window’s Background Image. . . . . 310
Drawing Custom Graphics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
The Fun and Practical Side of Working with Graphics . . . . . . . . . . 317
Ford634X.book Page xv Friday, April 14, 2006 12:29 PM
xvi
■CONTENTS
Building an MP3 Player . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317
Designing the User Interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
Setting Up the Menu System. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
Setting Up Property Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
Adding Program Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
Testing the RB MP3 Player . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321
■CHAPTER 12 Debugging REALbasic Applications . . . . . . . . . . . . . . . . . . . . . . 323
Tracking Down and Fixing Errors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323
Understanding Syntax Errors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324
Understanding Run-Time Errors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327
Understanding Logical Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328
Working with the REALbasic Debugger . . . . . . . . . . . . . . . . . . . . . . . . . . . 328
Setting Breakpoints. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329
Tracking Values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330
Using Break Points to Control Statement Execution . . . . . . . . . . . . 332
Developing Error Handlers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333
Handling Run-Time Errors with Exception Blocks . . . . . . . . . . . . . . 334
Handling Run-Time Errors with Try Blocks. . . . . . . . . . . . . . . . . . . . 337
Building a Network Connection Checker Application . . . . . . . . . . . . . . . . . 338
Setting Up the User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339
Adding Custom Properties and Methods. . . . . . . . . . . . . . . . . . . . . . 339
Adding a Little Program Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341
Testing the Network Connection Checker. . . . . . . . . . . . . . . . . . . . . 342
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343
PART 4 ■ ■ ■ Appendixes
■APPENDIX A Migrating Visual Basic Projects to REALbasic. . . . . . . . . . . 347
Porting Visual Basic Projects to REALbasic . . . . . . . . . . . . . . . . . . . . . . . . 347
Doing a Little Prep Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349
Importing Visual Basic Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349
REALbasic’s Project Converter Utility. . . . . . . . . . . . . . . . . . . . . . . . . 349
Ford634X.book Page xvi Friday, April 14, 2006 12:29 PM
■CONTENTS
xvii
■APPENDIX B What’s on the CD-ROM?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
REALbasic Program Source Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
■APPENDIX C What’s Next?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353
Locating REALbasic Resources Online . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353
REALbasic University . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353
RBDocs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353
RBGarage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353
VBZone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354
REALbasic Gazette . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354
Really Basic REALbasic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354
REALOPEN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354
Realgurus.com. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354
REALbasic Developer Magazine. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354
Joining REALbasic Mailing Lists. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356
■INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
Ford634X.book Page xvii Friday, April 14, 2006 12:29 PM
Ford634X.book Page xviii Friday, April 14, 2006 12:29 PM
xix
About the Author
■JERRY LEE FORD, JR. is an IT professional with over 16 years experience
in the industry. His background includes roles as an automation
analyst, technical manager, technical support analyst, automation
engineer, security analyst, and college instructor. Jerry has a master’s
degree in Business Administration from Virginia Commonwealth
University in Richmond, Virginia. He is an MCSE and a CISSP. Jerry is
the author of 17 other books, including Microsoft Visual Basic 2005
Express Edition Programming for the Absolute Beginner, Microsoft
VBScript Professional Projects, Microsoft Windows Shell Scripting and WSH Administrator’s
Guide, Learn VBScript: In a Weekend, Microsoft Windows Shell Script Programming for the
Absolute Beginner, Learn JavaScript: In a Weekend, and Microsoft Windows XP Professional
Administrator’s Guide. Jerry lives in Richmond, Virginia, with his wife Mary, and their children
Alexander, William, and Molly.
Ford634X.book Page xix Friday, April 14, 2006 12:29 PM
xx
About the Technical Reviewer
■ALLAN KENT is a born-and-bred South African, who still lives and works in Cape Town. He has
been programming in various and diverse platforms for over 20 years. Most recently, while on
the hunt for a viable cross-platform programming solution, Allan chanced upon REALbasic and
he hasn’t looked back since.
Ford634X.book Page xx Friday, April 14, 2006 12:29 PM
xxi
Acknowledgments
This book represents the hard work and efforts of numerous individuals. I would like to thank
Chris Mills, who served as the book’s lead editor, for working so hard and for providing me with
the opportunity to write this book. Special thanks go out to Allan Kent, the book’s technical
reviewer, for offering countless ideas and suggestions that helped make this a much better and
stronger book. I would also like to thank Marcia Baker, the book’s copy editor, for her dedica-
tion and professionalism, and for her patience in dealing with and fixing my many typos and
grammatical errors. I also want to acknowledge and thank Richard Dal Porto, the project
manager, for keeping me on schedule and making sure I didn’t forget to tie up any loose ends,
and Lori Bring, the book’s production editor, for guiding this book through its final stages.
Finally, I’d like to thank everyone else at Apress for all their hard work.
Ford634X.book Page xxi Friday, April 14, 2006 12:29 PM
xxii
Introduction
Welcome to Beginning REALbasic! REALbasic is a programming language that provides you
with everything you need to create software applications that can run on Macintosh, Windows,
and Linux. REALbasic is an extremely powerful programming language that is capable of
creating world-class software. Yet, at the same time, REAlbasic is easy to learn and makes a
perfect programming language for first-time programmers.
Using REALbasic, you can create applications, utility programs, and computer games. If
you are a Windows programmer, REALbasic provides you with all the tools you need to write
just about any Windows application imaginable: the same goes for Macintosh and Linux
programming. By supporting cross-platform application development, REALbasic significantly
enhances your ability to distribute your applications. This means you can share your work with
more friends and colleagues, and if you are in the business of developing commercial software,
REALbasic can help you attract new consumer markets.
Why REALbasic?
Plenty of programming languages are available today that are similar to REALbasic in many
aspects. On any given operating system (OS), they may come close to matching REALbasic’s
core set of features. However, none of the other major modern programming languages based
on the Basic programming language support application development on all three major
desktop OSs. This makes REALbasic unique and gives REALbasic programmers a competitive
advantage over other programmers.
As far as modern programming languages go, REALbasic is easy to learn, yet it is every bit
as powerful and full featured as any other modern programming language. So, whether you are
a student, a hobbyist, or a professional programmer, REALbasic has something to offer you.
REALbasic programmers are supported by a thriving user community and an array of third-
party developer support. This means you won’t have any trouble finding help or locating
companies that do REALbasic software development.
Unlike other programming languages, REALbasic does not require a complex framework
to execute. And, unlike Visual Basic .NET, REALbasic applications can run on older versions of
Windows, such as Windows 95 or 98, where the .NET Framework is not installed. REALbasic is
not restricted to a particular OS. In short, REALbasic is a modern, powerful, cross-platform,
object-oriented programming language that is friendly to beginners, yet powerful enough to
satisfy the most demanding programmers’ needs.
Who Should Read This Book?
The primary purpose of this book is to teach you how to develop applications using REALbasic
that can run on Macintosh, Windows, and Linux. Previous programming experience is not
required, although it certainly is helpful. This book is also designed to assist Visual Basic
Ford634X.book Page xxii Friday, April 14, 2006 12:29 PM
■INTRODUCTION
xxiii
programmers in making the jump over to cross-platform development using REALbasic. It
accomplishes this goal by pointing out key differences between the two programming
languages where appropriate throughout the book.
At a minimum, you need a good understanding of at least one of the OSs that REALbasic
runs on (Macintosh, Windows, or Linux). So, whether you are new to programming or an expe-
rienced programmer eager to make the transition to cross-platform application development,
this book can help you reach your goal.
What You Need to Begin
REALbasic supports cross-platform application development, meaning you can use it to
create applications that can be run on Macintosh, Windows, and Linux. To demonstrate and
reinforce REALbasic’s cross-platform development capabilities, this book was written using
versions of REALbasic that run on all three of these OSs. Therefore, you will see figures and
examples of applications running on any combination of these OSs. Except where specifically
noted, all the applications you learn how to create in this book run equally well on each OS.
Because of differences in how each OS is designed, however, you may notice small differ-
ences in the appearance of certain application features. I make every effort to point out where
differences occur and to ensure that the examples presented work equally well on Macintosh,
Windows, and Linux.
If you do not already have a copy of REALbasic installed on your computer, we have
provided Macintosh, Windows, and Linux trial versions on the book’s accompanying CD, along
with the source code for all the examples featured in the book. Once you have REALbasic
installed, you are prompted to enter a license key when you start it up. If you purchased REAL-
basic online, you receive your license key via e-mail. If you did not purchase REALbasic online,
you are prompted to automatically request a demo key via your Internet connection. This
enables you to try REALbasic free for ten days. Once this is done, you are ready to go.
Along with this book, we provide everything you need to begin developing world-class soft-
ware applications for Macintosh, Windows, and Linux!
How This Book Is Organized
Beginning REALbasic is organized into four parts.
Beginning REALbasic is designed to be read sequentially from cover-to-cover. However,
more experienced programmers and programmers with previous BASIC programming experi-
ence may want to use this book by reading the first few chapters, and then skipping around and
selecting the chapters that interest them the most.
Part 1: Introducing REALbasic
This section is made up of two chapters that are designed to provide you with a solid introduc-
tion to REALbasic and its integrated development environment.
Ford634X.book Page xxiii Friday, April 14, 2006 12:29 PM
xxiv
■INTRODUCTION
Part 2: Learning How to Program with Realbasic
This section consists of six chapters, each of which addresses a specific programming topic.
These topics include interface development, menu development, storing and retrieving data,
conditional logic, loops, and object-oriented programming.
Part 3: Advanced Topics
The Advanced Topics section, which is made up of four chapters, covers processing files,
creating and accessing databases, and working with graphics and audio.
Part 4: Appendixes
This section is made up of three appendixes that address porting a Visual Basic application over
to REALbasic, the contents of the book's CD-ROM, and different resources available to you as
you continue learning about REALbasic.
Conventions Used in This Book
One of the goals I had in writing this book was to make it as clear and easy to understand as
possible. Throughout the book, you will find a number of special elements designed to make
reading and working with the presented material easier. The following provides a quick review
of these special elements.
■Tip Tips are suggestions that point out different ways of accomplishing tasks or helping you to work more
efficiently and effectively.
■Note Notes are designed to provide you with additional information about a topic being discussed or to
bring additional emphasis to a particular point.
SIDEBAR
Sidebars are designed to provide you with information that, while not necessarily essential to the topic being
discussed, is still important and worth learning. Sidebars are also used to identify real-world situations where
REALbasic can be applied.
Ford634X.book Page xxiv Friday, April 14, 2006 12:29 PM