Porting Visual Basic Projects to Realbasic

Porting Visual Basic Projects to Realbasic

PART 4 ■ ■ ■ Appendixes APPENDIX A ■ ■ ■ Migrating Visual Basic Projects to REALbasic If you are a Visual Basic programmer looking to make the jump to REALbasic, you probably have Visual Basic applications you want to migrate over as well. REALbasic and Visual Basic share a great many similarities. As such, there is no reason why you cannot convert most of your applications over to REALbasic. This way, not only can you run them on Windows, but you also can port them over to Macintosh and Linux. Specifically, you learn • How to prepare your Visual Basic code for migration • How to import Visual Basic projects into REALbasic projects • How to use the REALbasic Project Converter Porting Visual Basic Projects to REALbasic Depending on the size and complexity of your Visual Basic projects, the challenge of convert- ing your applications may seem daunting. However, you can do a number of things to make the process go smoother and to save yourself considerable time and effort. You should be able to reuse most of your Visual Basic code in your new REALbasic appli- cations. However, many little differences exist between the two programming languages. This should not be surprising given Microsoft’s Windows centric approach to programming language implementation. REALbasic, on the other hand, has been implemented using a cross-platform approach that stresses code portability. 347 348 APPENDIX A ■ MIGRATING VISUAL BASIC PROJECTS TO REALBASIC A sampling of differences between Visual Basic and REALbasic include the following: • Differences in supported data types. For example, Visual Basic supports the Long data type and REALbasic does not. Instead, you should use REALbasic Integer data type. Visual Basic also supports the Currency data type, for which REALbasic has no equivalent. • Differences in classes and data types. For example, in REALbasic the Date is handled as a class, whereas in Visual Basic, the Date is made available as a built-in data type. • Differences in variable declaration. REALbasic forces you to declare all variables using the Dim keyword. Visual Basic enables you to dynamically create variables, making Option Explicit an optional statement. • Differences in variable naming rules. In REALbasic, variable names must begin with a letter and are made up of alphanumeric characters. However, Visual Basic variable names can also contain special characters (%, @, &, $, and so forth) leading to potential conflicts. • Differences in keywords. A valid variable in one language may result in a keyword con- flict in the other language. • Differences in operators. For example, in Visual Basic, concatenation is performed using the ampersand (&) character, whereas REALbasic uses the plus (+) character. • Differences in the way some keywords are implemented. For example, in Visual Basic, the Mid function can be used to return a substring or to perform a substring replace- ment. In REALbasic, the Mid function can only be used to return a substring. • Differences in the naming of the same functions. For example, REALbasic has LowerCase and UpperCase functions, whereas Visual Basic has LCase and UCase functions. • Differences in the application of conditional logic. Unlike Visual Basic, REALbasic does not support single line Case statements. • Differences in the formation of loops. REALbasic does not support the setup of a loop index on the Next statement in a For…Next loop the way Visual Basic does. Visual Basic supports the creation of loops that iterate negatively, using the To and Step keywords. REALbasic replaces these keywords with the DownTo keyword. • Differences in how functions operate. Visual Basic allows functions to return a result by setting a value equal to the name of the function. REALbasic requires you to use the Return statement. • Differences in how parameters are supported. Instead of supporting optional parame- ters, REALbasic provides the capability to set up default values for parameters. • Differences in file system access. Visual Basic using a Windows-specific approach to accessing the file system, whereas REALbasic uses an operating system independent- access approach. APPENDIX A ■ MIGRATING VISUAL BASIC PROJECTS TO REALBASIC 349 As you can see from this brief sampling, the differences between Visual Basic and REAL- basic are far too numerous to outline in this appendix. Instead, this appendix is designed to provide you with an overview of your options for converting Visual Basic projects to REALbasic projects and to outline the basic steps involved. Doing a Little Prep Work You can take a number of simple steps prior to converting your program code that can signifi- cantly simplify the migration process. For starters, review your Visual Basic code and, if necessary, change it so all variables are formally declared. Also, ensure that all variable names conform to REALbasic’s rules. You should spend a little time checking on the data types being used, as well, and change them if necessary. And, while you’re at it, keep an eye on variable names, as well as subroutine and function names to make sure they are not in conflict with any REALbasic keywords. Importing Visual Basic Projects REALbasic provides you with the capability to import any Visual Basic 2 or later form, along with all associated code into REALbasic projects. In doing so, REALbasic automatically re-creates Visual Basic forms as REALbasic windows. In addition, REALbasic creates event handlers and methods to store any program code imported along with the Visual Basic forms. The following procedure outlines the steps involved in importing a Visual Basic form into a REALbasic project: 1. Locate the Visual Basic form you want to import. 2. Create a new REALbasic project or open the REALbasic project into which you want to import a Visual Basic form. 3. Drag-and-drop the Visual Basic form into the REALbasic Project Editor screen. Depending on the complexity of the program code imported along with a Visual Basic form, you may not need to do anything else to get your project to compile under REALbasic. In most cases, though, you’ll have some code statements that REALbasic was unable to convert. To find out, try to compile your new REALbasic application and, if necessary, fix any reported errors. REALbasic’s Project Converter Utility In addition to importing your Visual Basic forms directly into REALbasic projects, you can use the Visual Basic Project Conversion Utility to assist in the conversion of entire Visual Basic projects to REALbasic projects. This utility is available free: simply download it from the REALbasic web- site (www.realbasic.com/downloads/). According to its documentation, the Visual Basic Conversion Utility is designed to assist in converting Visual Basic 4.x to 6.x projects to REALbasic projects. This utility is not intended as a tool for converting Visual Basic .NET applications. You install the Visual Basic Project Conversion Utility by downloading and decompressing it in the desired location on your computer. Once installed, you can use it to convert Visual Basic projects by dragging-and-dropping the Visual Basic projects on to the utility. The utility 350 APPENDIX A ■ MIGRATING VISUAL BASIC PROJECTS TO REALBASIC then analyzes all the Visual Basic project’s files. The Visual Basic Project Converter Utility auto- matically converts Visual Basic projects, forms, classes, modules, and program code into equivalent REALbasic projects, windows, classes, modules, and program code. Although, this utility can completely convert simple Visual Basic projects to REALbasic projects, it cannot convert most projects without a little help on your part. For example, you will probably have to rewrite certain portions of program code. In addition, any controls found in Visual Basic applications for which corresponding controls do not exist in REALbasic need to be converted to Canvas controls, leaving it up to you to create your own replacement con- trols or equivalent functionality. The Visual Basic Project Converter Utility’s database support is limited. Any database connections found in a Visual Basic project will not be re-created within REALbasic projects. Neither will a database be added to your REALbasic project. Instead, you must go back and reestablish the database connection, and then reset the DataField and DataSource properties for all controls bound to the database. APPENDIX B ■ ■ ■ What’s on the CD-ROM? When it comes to being a good REALbasic programmer, no substitute exists for hands-on experience in creating and testing REALbasic applications. It helps to have a collection of application source code from which you can learn and experiment. By studying and copying code examples from other REALbasic projects, you can also save time when creating new applications. This book’s companion CD-ROM provides access to all the sample applications presented in this book. This book’s companion CD-ROM also provides you with convenient access to copies of REALbasic 2006 for Macintosh, Windows, and Linux. REALbasic Program Source Code This book was written with the intention that you create and experiment with each of the sam- ple applications presented in the chapters as you make your way through the book. However, in the event that you may not have had the time to create and test every application presented, you can find copies of each sample application on this book’s companion CD-ROM. Table B-1 provides you with a quick review of each of the sample applications you will find. Table B-1. REALbasic Projects Available on This Book’s Companion CD-ROM Chapter Application/Project Description Chapter 1 Hello World.rbp A Hello World! Application Chapter 2 RBBookFinder.rbp The RBBookFinder Browser Chapter 3 RBClock.rbp A Desktop Clock Application Chapter 4 RBQuickNote.rbp The RBQuickNote StickyPad Application Chapter 5 RBCalculator.rbp A Desktop Calculator Chapter 6 RB NumberGuess.rbp The RB Number Guess Game Chapter 7 RB Movie Player.rbp The RB Movie Player Chapter 8 Picture Viewer.rbp The RB Picture Viewer StatesListbox.rbo A custom ListBox Control of State Names Chapter 9 RB Word Processor.rbp The RB Word Processor Continued 351 352 APPENDIX B ■ WHAT’S ON THE CD-ROM? Table B-1.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    27 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us