Google
www ResExcellence

Application Makeovers
Desktop Snapshots
iTunes Skins
Mighty Mouse Cursors
Uploads
Boot Images
Dock Poofs
Links List
Photoshop Goodies
Users Forum
Boot Panels
Download Stats
Log-In Panels
REALbasic
Clocks
GUI Software
Mac OS X Mods
Safari Stuff
Desktop Pictures
Icons
Mac OS X Themes
Splash Screens
Homepage
Download a free demo of REALbasic!
Download a free demo of REALbasic!
Recent Articles...
3D
3D Photo Gallery (Part 2)
3D Photo Gallery (Part 1)

Audio
iPod Tricks (Part 3)
iPod Tricks (Part 2)
iPod Tricks (Part 1)
Laugh Track Machine
Audio Player with Reverb
Shepard Melody
RB Phone Home
Build a Drum Machine

Custom Controls
Custom Buttons
Custom Buttons Part II
iTunes-style Listboxes
Custom Controls

General RB
Wiggle Window
JPEG in PDF
Hey! You got your Checkbox in my Listbox!
Background Applications
Listbox Auto-Find
Virtual Volumes
Time Tracker
Software Distribution (Part 4)
Software Distribution (Part 3)
Software Distribution (Part 2)
Software Distribution (Part 1)
Exceptions
Living on the Edge
Tips and Tricks
Review of REALbasic 3.0
Text Clippings Made Easy

Graphics
Image Spinner
Cropping Graphics (Part 4)
Cropping Graphics (Part 3)
Cropping Graphics (Part 2)
Cropping Graphics (Part 1)
Shimmer Graphics
Lissajous Figures
Simple Screen Capture
Vector Graphics
Kaleidoscope Images
Stegonography
Spirals!
Image Table
RB Magnifying Lens
Screen Capture
Color Picker Tutorial

Hacks
Ghost Grab
Speedy Mouse Extension
iTunes Plugins
iTunes Skinner

Internet
Display Web Image In Canvas
HTML IMG Tags
Version Tracking
Even Smarter Instant Messaging
Web Tiler
JavaScript and REALbasic
Stock Ticker (Part 2)
Stock Ticker (Part I)
AIM Mate

Mac OS X
Using Sheets in REALbasic
Build a Bundle (Part 2)
Build a Bundle (Part 1)
Dock Your Passwords
Mac OS X Debugging
REALbasic Mac OS X Icon Tutorial
Animate Your Dock
RB and the Command Line

Novelty
Guessing Game
Calendar Trivia
Tile Mixer
Zip Code Finder
Happy Valentine's Day
Merlin Simulator (Part 3)
Merlin Simulator (Part 2)
Merlin Simulator (Part 1)
Buzzword Machine
AppleSoft BASIC

Printing
Print to PDF

Registration
Registration Code Validation

Resources
Picture Extractor (Part 2)
Picture Extractor (Part 1)

Serial
Caller ID (Part 3)
Caller ID (Part 2)
Caller ID (Part 1)

Speech
Speech Recognition

Video
Big Brother Video Capture

Newest Dev Tools!

Book Alert !
REALbasic for Dummies
by Erick Tejkowski
$19.99 @ Amazon

Made with REALbasic!

Problems?
Downloads are in StuffIt 5 format (free download).
Tell me about a bad link (Thanks!).
Submission Policy

3-7-02

ResExcellence Zip Code Finder by Erick Tejkowsi

Today we'll build a simple tool to look up U.S. zip codes. Using only a zip code, we can learn the precise location of an address and calculate the distance from that location to any other place in the country.

Intro

This project is a clone of a Cocoa-based open source project. I thought the idea was fun and pretty useful, so I decided to convert it into a REALbasic project for ResExcellence readers. The zip code data that accompanies this project is a collection of numbered text files. These files comprise a complete (as of 1999) collection or "database" of all the zip codes in the United States. Accompanying each zip code is a city name, longitude, and latitude for location. In addition to these zip code data files, there are two files that contain the states and time zones of the various zip codes.

Our project will simply accept a zip code and attempt to find it in the zip code files. Once a match is found, the various information is pulled from the database. An enterprising REALbasic user might consider moving all of this data into a REAL Database for additional database manipulation abilities.

Build the Interface

The interface is the most time-consuming aspect of today's project. It's not really difficult to build, but its a bit tedious. If you'd prefer not to build the interface, you can download the finished project at the end of this tutorial.

Begin by launching REALbasic and open Window1 by double-clicking it in the Project Window. To this window add the following controls:

Control TypeNameOther Info
EditFieldZipField 
RadioButtonRadioButton1Location1
RadioButtonRadioButton2Location2
PushButtonPushButton1Find Zip
PushButtonPushButton2Calculate
StaticTextloclabelIndex=0
StaticTextloclabelIndex=1
StaticTextstatelabelIndex=0
StaticTextstatelabelIndex=1
StaticTextlonglabelIndex=0
StaticTextlonglabelIndex=1
StaticTextlatlabelIndex=0
StaticTextlatlabelIndex=1
StaticTextzonelabelIndex=0
StaticTextzonelabelIndex=1
StaticTextdistancelabel 

You can add labels and GroupBoxes to spruce things up as you see fit, but your completed interface might look like this:

03-07-02_interface.jpg (18k)

Add the Code

The code segment of this tutorial is pretty easy to digest. You will need to place code in the Action events of PushButton1 and PushButton2. For starters, navigate to the Action event of PushButton1 and add this code:

  dim s,temp,remainingzip as string
  dim lasttemp as string 
  dim textin as textinputStream
  dim f as folderItem 
  dim foundone as boolean 
  dim tempnum,group as integer
  
  if radioButton1.value then
    group = 0
  else
    group = 1
  end if
  
  if len(ZipField.text)<>5 then
    msgBox "Zip code must be 5 digits long"
    return
  end if
  
  // FIND :
  // ZIP CODE LOCATION (CITY)
  // LONGITUDE
  // LATITUDE
  s = left(ZipField.text,2)
  remainingzip = right(ZipField.text,3)
  foundone = FALSE
  f = GetfolderItem("zipcodes").child(s+".txt")
  if f<>nil and f.exists then
    textin = f.openastextFile
    while not(textin.eof)
      temp = textin.readline
      if left(temp,3)=remainingzip then
        //we found a match !
        longlabel(group).text = "-"+mid(temp,4,9)
        latlabel(group).text = mid(temp,14,9)
        loclabel(group).text = right(temp,len(temp)-22)
        foundone = TRUE
      end if
    wend
    textin.close 
    
    // FIND :
    // ZIP CODE LOCATION (STATE)
    if foundone then
      f = GetfolderItem("zipcodes").child("states.txt")
      if f<>nil and f.exists then
        textin = f.openasTextFile
        foundone=FALSE
        while not(textin.eof) AND foundone=FALSE
          temp = textin.readline
          tempnum = val(left(temp,5))
          if tempnum>val(zipField.text) then
            //found the state!
            foundone=TRUE
            statelabel(group).text = right(lasttemp,2)
          end if
          lasttemp = temp
        wend
        textin.close 
      end if
      
      //FIND :
      // TIME ZONE
      f = GetfolderItem("zipcodes").child("zones.txt")
      if f<>nil and f.exists then
        textin = f.openasTextFile
        foundone=FALSE
        while not(textin.eof) AND foundone=FALSE
          temp = textin.readline
          tempnum = val(left(temp,5))
          if tempnum>val(zipField.text) then
            //found the time zone!
            foundone=TRUE
            zonelabel(group).text = right(lasttemp,len(lasttemp)-5)
          end if
          lasttemp = temp
        wend
        textin.close 
      end if
      
    else
      MsgBox "Zip code not found."
    end if
    
  end if
  
  

Finally, navigate to the Action event of PushButton2 and enter this code:

  dim distance,lat1,lat2,long1,long2 as double
  dim x,y as double
  
  lat1 = val(latlabel(0).text)
  lat2 = val(latlabel(1).text)
  long1 = val(longlabel(0).text)
  long2 = val(longlabel(1).text)
  
  x = 69.1 * (lat2 - lat1)
  y = 53 * (long2 - long1)
  //Approximate distance in miles
  distance = sqrt(x * x + y * y)
  distancelabel.text = format(distance,"########")+" miles"

These two pieces of code scan through the various text files to track down the city, latitude, longitude, and time zone of the desired zip code. From this information, we calculate a distance. Accompanying the original open source project as well as the download for this tutorial is a short document that lists additional distance calculations. We used the simplest (but most error-prone) calculation for the distance. You might try your hand at the others to see how they differ.

Conclusion

That's it for this week. You can download the completed project here. See you next week!


3-5-02

REALbasic News by Erick Tejkowsi

03-06-02_rbdev.jpg (13k)

New REALbasic Magazine! A new REALbasic magazine named REALbasic Developer is scheduled for a debut release at MacWorld NY this summer. REALbasic Developer is a bimonthly magazine focusing on programming with REALbasic. It is the ultimate source for industry news, product reviews, tips, tutorials, software design techniques, business and marketing ideas, and lessons on advanced features. It caters to the hobbyist, semi-professional, and professional programmer. The magazine features content from the top writers in the field, and includes regular columnists that focus on key topics, such as learning to program, compiling for the Windows platform, and basic algorithms, as well as four or five in-depth features on topics of critical importance to readers.

The Editorial Board of REALbasic Developer is made up of some names you might recognize:

Image Manipulation Michio Ono has updated another one of his great tools. Micono Perspective plugin is a plugin for rotating and scaling images, to name a few of its functions. The demo is really nice and this sucker is FREE. Cool!

MacInternetConfig Paul Mitchum has posted a new plugin. MacInternetConfig is a free plugin that allows you access to the InternetConfig API from directly within REALbasic. MacInternetConfig works with 68k-, PPC-, and Carbon-based Macintoshes.

Lua Plugin amianduri is now offering Lua Plugin, a REALbasic plugin that allows execution of Lua scripts. The API is similar to the RBScript API. There is a Print event that is called when Lua wants to print something, and an Input event when Lua needs input from the user. Lua Plugin has been built with Lua 4.0.

Round Buttons Will Cosgrove has added Classic support to Round Navigation Button plugin. It now works on systems as far back as Mac OS 8.5.

More Round Buttons As an alternative to Will Cosgrove's great Round navigation button plugin Joerg Pressel has made his cRoundButton classes available to the public.


Application Makeovers
Desktop Snapshots
iTunes Skins
Mighty Mouse Cursors
Uploads
Boot Images
Dock Poofs
Links List
Photoshop Goodies
Users Forum
Boot Panels
Download Stats
Log-In Panels
REALbasic
Clocks
GUI Software
Mac OS X Mods
Safari Stuff
Desktop Pictures
Icons
Mac OS X Themes
Splash Screens
Homepage

Maintained by the Staff of ResExcellence. This entire site ©1997-2003 ResExcellence
Privacy Statement? Sure we gotta Privacy Statement.

[an error occurred while processing this directive]on the ResEx LinuxPPC Server