ok, so I'm writing VBA code for an excel spreadsheet and Mappoint 2004, that returns the road distance between two locations, using their Lat and Long...
The trouble is when I get to an isolated Postal Code (or Zip Code) that doesn't have road access connecting the mainland I get some error (can't even identify it) and Mappoint shuts down, the excel macro suts down, leaving me "up the creek"...
I've attached the code, and appreciate any help or hints... (My next step will be to identify manually which Zip Codes are isolated, and then have a seperate "straightline distance calculator" return a distance for the isolated location...
Here's the code:
>>>>>>>>>>>>>>>>>>>
Public Function RoadDistance(Lat1, Long1, Lat2, Long2)
Dim SysApp As New MapPoint.Application
Dim SysMap As MapPoint.Map
Dim SysRoute As MapPoint.Route
Dim SysLoc1 As MapPoint.Location
Dim SysLoc2 As MapPoint.Location
Application.ActivateMicrosoftApp xlMicrosoftMappointNorthAmerica
Application.DisplayAlerts = False
'SysApp.OpenMap (AKPath & "\LHIN.ptm")
Set SysMap = SysApp.ActiveMap
Set SysRoute = SysMap.ActiveRoute
SysApp.Units = 1
Set SysLoc1 = SysMap.GetLocation(Lat1, Long1)
Set SysLoc2 = SysMap.GetLocation(Lat2, Long2)
SysRoute.Waypoints.Add SysLoc1
SysRoute.Waypoints.Add SysLoc2
SysRoute.Calculate
On Error GoTo IsolatedPC
'Sheets("Maps").Select
RoadDistance = SysRoute.Distance
SysRoute.Clear
SysMap.Saved = True
GoTo Ending
IsolatedPC:
SysRoute.Clear
SysMap.Saved = True
RoadDistance = Posdist(Lat1, Long1, Lat2, Long2)
Ending:
End Function
>>>>>>>>>>>
any thoughts?
cheers,
andriy