PDA

View Full Version : How Do I Refer to Address Data for Calculating Distance?



joent
07-05-2012, 03:19 PM
' The following works using hard-coded strings (from FindAddressResults example)

oRoute.Waypoints.Add oMap.FindAddressResults("One Microsoft Way", "Seattle", , "WA").Item(1)
oRoute.Calculate
MsgBox "Miles: " & CStr(oRoute.Distance)

' Trying to work through active map with Data Imported Name, Address, City, State, Zip fields:
For i = 1 To oWps.Count
oRoute.Waypoints.Add oMap.FindAddressResults(.Address, .City, , .State).Item(i)
oRoute.Calculate
MsgBox "Miles: " & CStr(oRoute.Distance)
Next i

I get an error beginning with .Address.
How can I better refer to addresses coming from the Waypoints to calculate distance between waypoints?

Thanks

Eric Frost
07-06-2012, 12:39 PM
Hi Joe NT!

I'm not actually sure what you are trying to do. If you are going to use .Address (or .City or .State) you would need a With statement.

The StreetAddress object which is a property of a Location object returned by FindAddressResults has the following properties --

Application
City
Country
OtherCity
Parent
PostalCode
Region
Street
Value*

Perhaps you could post a little Excel macro with the data and code and we can work through it?

Eric

Winwaed
07-09-2012, 08:05 AM
Yes it looks like you are missing a With statement (at the least).

Also note that you areare adding each of the results from FindAddressResults() to the route, but you are looping over the number of waypoints. This will not work, and will either do nothing or produce an exception in most cases.

Also note that you are assuming FindAddressResults() is returning a valid result. It can return a range of results including "ambiguous" (a collection of possible matches, no guarantee that the first is anywhere near correct) and simply not found. You should check the ResultsQuality property first before blindly accessing Item(1).