MapBasic 101
A 20 Minute Intro Lesson For Beginners
Presented at the Puget Sound MapInfo User Group
April 3, 1996
John Schlosser
Schlosser Geographic Systems, Inc.
206-224-0800
Three Problems Solved by MapBasic
- Problem #1: MapInfo is too complex: E.g., Basic menu and button bars are too complicated for the simple things some users
need to do. MapInfo terminology (in menu choices, for example) doesn't speak to your users.
Solution: Use MapBasic to simplify MapInfo. For example, create a shorter menu, fewer or custom buttons, and/or custom
dialog boxes that prompt for specific user information using language users understand.
- Problem #2: MapInfo out-of-the-box can't do it. For example, you want to create contour lines from point data, create
grids that are exactly 50 miles on a side, or automatically draw lines that connect a series of points.
Solution: Use MapBasic to do it. You can do nearly anything with it. If MapInfo's commands and functions are not enough or
too slow, MapBasic can call C programs, or other external programs to do the work, then display the results in MapInfo
- Problem #3: You need to repeatedly do nearly the same thing. E.g., Assemble and print a map, each month, showing clients,
activity or sales by census tract; Assemble and print a map of the vicinity around each of 500 locations scattered throughout
the US; Import 50 files from DXF format, then change the line styles to fit your predefined pattern. This is not a problem of
whether or not MapInfo can do the task or that MapInfo is too complicated. You just want to get MapInfo to run
automatically.
Solution: Use MapBasic to automate the processing. Typically that means looping through a list (table) of stores, sites,
clients, etc., and doing the same thing for each record in the table.
Key Stages in Learning MapBasic
- Your first MapBasic program can simply be a MapBasic command (or commands) typed in the MapBasic window.
Keep your MapBasic Window open all the time.
This is called using MapBasic without buying MapBasic.
- Your second MapBasic program can be an edited Workspace file.
Read your Workspace files.
Use a word processing program or text editor to view or print.
As long as you avoid variables you can do this without buying MapBasic.
- Modify and customize template code (filched from the MapBasic window or WOR file), to enhance extend your
code.
For a template, copy code that MapInfo automatically prints to the MapBasic window and/or cut and paste code from a
Workspace file. For example, you can customize the code by adding variables, dialog boxes etc.
- Use MapBasic to make your own life easier, before programming code for others to run. Writing code for others to run
is MUCH more complicated. It requires lots of code simply to trap for mistakes that darn user will make.
4 Strategies to Troubleshoot Code and Avoid Problems
- Document your code with lots of comments. In MapBasic, lines beginning with an apostrophe [ ` ]are comments.
- Create and follow standardized conventions about naming variables. Eg., All String variables have names that start with s
(eg. sMyName); SmallInt variables have names that start with m (eg, mPop_1990).
- Test problem code fragments in the MapBasic window.
- Borrow code from sample MapBasic applications included with MapBasic. Search the sample code for occurrences of use
of a specific MapBasic command that is troubling you.
- Get structural. Take a programming class (e.g., in MapBasic or Visual Basic). Learn how to make your code modular
with an efficient structure.
All rights reserved, Schlosser Geographic Systems, Inc. Seattle, WA 206-224-0800. Permission is granted to reproduce
this document for non commercial purposes, provided that the document is reproduced in its entirity, including this
notice.