ZipCode Distances

1. Senior Member
Join Date
Dec 1969
Posts
106

## ZipCode Distances

I have a series of zipcodes with a distance affiliate with each one. I want to order the distance and keep the order of the zipcodes as well. For example:<BR><BR>Before Order:<BR>94115=10<BR>94116=5<BR>94117=6<BR><BR>Wh at I want to achieve:<BR>94116=5<BR>94117=6<BR>94115=10<BR><BR> But what I get:<BR>94115=5<BR>94116=6<BR>94117=10<BR><BR>My problem is that when I order the distances (using split and an order function), I lose the order of the relationship bwtn the zipcode and the distance. How can I keep the relationship?<BR><BR>thx<BR><BR><BR>

2. Senior Member
Join Date
Dec 1969
Posts
1,944

## Are they two

fields in the database?

3. Senior Member
Join Date
Dec 1969
Posts
106

## RE: Are they two

No, the distance calculation is separate from the db.

4. Senior Member
Join Date
Dec 1969
Posts
1,944

## let me see the

sort function.

5. Senior Member
Join Date
Dec 1969
Posts
106

## RE: let me see the

Here is a snap shot of the code:<BR><BR>Sort Function......<BR>&#060;script language=JScript runat=server&#062;<BR> function SortVBArray(arrVBArray) {<BR> return arrVBArray.toArray().sort(sNumAsc).join(&#039;&#0 39;);<BR> }<BR> // Sorts records in ascending<BR>// numeric value order<BR>function sNumAsc(a, b) {<BR> return ((+a &#062; +b) ? 1 : ((+a &#060; +b) ? -1 : 0));<BR>}<BR>&#060;/script&#062;<BR>&#060;%<BR> Function SortArray(arrInput)<BR> SortArray = Split(SortVBArray(arrInput), Chr(8))<BR> End Function<BR><BR>------------<BR>Do Until oRs.EOF<BR>zipp=oRs("zipcode")<BR>latt=oRs("latitu de")<BR>longg=oRs("longitude")<BR>zipdist=Round(Ge tDistance(iStartLat, iStartLong, latt, Longg, "M"),0)<BR><BR>ZipDistList=ZipDistList & zipp & "=" & zipdist & ","<BR>oRs.MoveNext<BR>Loop<BR><BR>.....breakd own ZipDistList using Split and Function SortArray<BR>-----------------<BR><BR>%&#062;

6. Senior Member
Join Date
Dec 1969
Posts
1,944

## sorry, no clue.

/

7. Senior Member
Join Date
Dec 1969
Posts
96,118

## Easy enough...

Just convert:<BR><BR>94115=10 to 10.94115<BR>94116=5 to 5.94116<BR>94117=6 to 6.94117<BR><BR>Make sure all the converted values are *NUMBERS* (use the CDBL function to convert them after transforming the strings).<BR><BR>Sort the *NUMBERS* and then you can convert them back to strings, pull the pieces apart at the period, and (if you really need to) stick them back together with an = sign in the other order.<BR><BR>

8. Senior Member
Join Date
Dec 1969
Posts
1,944

## Oh,I Guess i was looking at it too... deep <e

.

9. Senior Member
Join Date
Dec 1969
Posts
106

## RE: Easy enough...

As always Bill, you are a life saver!

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•