MACSCRPT Archives

March 2009

MACSCRPT@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
"Stockly, Ed" <[log in to unmask]>
Reply To:
Macintosh Scripting Systems <[log in to unmask]>
Date:
Thu, 19 Mar 2009 17:26:38 -0700
Content-Type:
text/plain
Parts/Attachments:
text/plain (68 lines)
This is a pure appleScript method, based on a routine found here:
'http://www.csgnetwork.com/directzip2state.html'

I just ran over a hundred randomly selected zip codes through and it seemed
to work.

I prefer this to greping a file, and this could probably be sped up using
script objects.

ES
Property zipCodeList :{}
my SetZipList()
set myZip to "87544"
set myState to my StateFromZip(myZip)

on StateFromZip(aZip)
    set oldDelims to AppleScript's text item delimiters
    set AppleScript's text item delimiters to {""}
    set aZip to ((characters 1 thru 3 of aZip) as text) as integer
    set AppleScript's text item delimiters to oldDelims
    repeat with thisRange in zipCodeList
        set {state, low, high} to thisRange
        if aZip „ low and aZip ¾ high then
            return state
        end if
    end repeat
    return "" --invalid zipcode or error
end StateFromZip


on SetZipList()
    --as per 'http://www.csgnetwork.com/directzip2state.html'
    set zipCodeList to {{"AL", 350, 369}, {"AK", 995, 999}, {"AZ", 850,
865}, ¬
        {"AR", 716, 729}, {"AR", 755, 755}, {"AS", 967, 967}, {"CA", 900,
966}, ¬
        {"CO", 800, 816}, {"CT", 60, 69}, {"DC", 200, 205}, {"DE", 197,
199}, ¬
        {"FL", 320, 342}, {"FL", 344, 344}, {"FL", 346, 347}, {"FL", 349,
349}, ¬
        {"GA", 300, 319}, {"GU", 969, 969}, {"HI", 967, 968}, {"ID", 832,
838}, ¬
        {"IL", 600, 629}, {"IN", 460, 479}, {"IA", 500, 528}, {"KS", 660,
679}, ¬
        {"KY", 400, 427}, {"LA", 700, 714}, {"ME", 39, 49}, {"MH", 969,
969}, ¬
        {"MD", 206, 219}, {"MA", 10, 27}, {"MA", 55, 55}, {"MI", 480, 499},
¬
        {"MN", 550, 567}, {"MS", 386, 397}, {"MO", 630, 658}, {"MT", 590,
599}, ¬
        {"NE", 680, 693}, {"NV", 889, 898}, {"NH", 30, 38}, {"NJ", 70, 89},
¬
        {"NM", 870, 884}, {"NY", 90, 149}, {"NY", 4, 4}, {"NY", 63, 63}, ¬
        {"NC", 269, 289}, {"ND", 580, 588}, {"MP", 969, 969}, {"OH", 430,
458}, ¬
        {"OK", 730, 749}, {"OR", 970, 979}, {"PA", 150, 196}, {"PR", 6, 9},
¬
        {"RI", 28, 29}, {"SC", 290, 299}, {"SD", 570, 577}, {"TN", 370,
385}, ¬
        {"TX", 750, 799}, {"TX", 885, 885}, {"UT", 840, 847}, {"VT", 50,
59}, ¬
        {"VA", 220, 246}, {"VA", 201, 201}, {"VI", 8, 8}, {"WA", 980, 994},
¬
        {"WI", 530, 549}, {"WV", 247, 268}, {"WY", 820, 831}, {"AE", 90,
98}, ¬
        {"AA", 340, 340}, {"AP", 962, 966}}
end SetZipList

ATOM RSS1 RSS2