Community of VE/MapPoint Users and Developers
This is a discussion on How to handle route calculation error within the MapPoint 2006/2009 Discussion forums, part of the Map Forums category; Hi all. I am trying to write a simple VB script that is executed from Access to calculate the driving ...
| |||||||
| Register | Blogs | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| |||
| How to handle route calculation error I am trying to write a simple VB script that is executed from Access to calculate the driving distance from one zip code to another and write the distance back to a table. I have the base script (see below) working, but I am running into a problem that when a good route can not be calculate by MapPoint the script bombs. I am looking for a away to write a default number (i.e. 999999) as the distance when a route can not be calculated so that the script does not bomb each time. Any ideas (and examples) would greatly be appreciated. Thanks Rolf MapPoint Error: "Unable to get directions from 71, East Lyme, CT 06333 to 330th St, White Hall, AR 71602. One of the areas may not contain necessary connectors such as ferry routes or main roads. Move one or both of the stops, and try again." Script: Private Sub Command0_Click() Dim objApp As New MapPoint.Application Dim objMap As MapPoint.Map Dim objRoute As MapPoint.Route Dim strfromcity As String Dim strfromstate As String Dim strtocity As String Dim strtoState As String Dim strfromlocation As String Dim strtolocation As String Dim strfromzip As String Dim strtozip As String Dim fromLong As Double Dim fromLat As Double Dim toLong As Double Dim toLat As Double Dim CalcTime As Date Dim dbs As Database Dim rstmilage As DAO.Recordset Dim n As Double 'Set up the application Set objMap = objApp.ActiveMap Set objRoute = objMap.ActiveRoute objApp.Visible = False objApp.UserControl = True 'Open Route Stops Table and interates through Table Set dbs = CurrentDb Set rstmilage = dbs.OpenRecordset("tblMilage", dbOpenTable) With rstmilage .MoveFirst Do While Not rstmilage.EOF strfromzip = Nz(![fromzip]) strtozip = Nz(![tozip]) 'Add route stops and calculate the route objRoute.Waypoints.Add objMap.FindResults(strfromzip).Item(1) objRoute.Waypoints.Add objMap.FindResults(strtozip).Item(1) CalcTime = Now() If objRoute.Waypoints.Count > 1 Then objRoute.Calculate m = objRoute.Directions.Count rstmilage.Edit rstmilage("MPZipDist") = objRoute.Directions.Item(m).ElapsedDistance rstmilage("Create_Time") = CalcTime objRoute.Clear rstmilage.Update rstmilage.MoveNext objRoute.Clear Else rstmilage.Edit rstmilage("MPZipDist") = "999999" rstmilage("Create_Time") = CalcTime objRoute.Clear rstmilage.Update rstmilage.MoveNext objRoute.Clear End If Loop rstmilage.Close End With objApp.Quit MsgBox "All Done" End Sub |
| |||
|
This should give you some ideas: (additions commented and marked with asterisks) Code: Private Sub Command0_Click()
.
.declarations were here
.
'**** add error handler ****
On Error GoTo ProcessError:
'************************
'Set up the application
Set objMap = objApp.ActiveMap
.
.set up stuff here
.
With rstmilage
.MoveFirst
Do While Not rstmilage.EOF
strfromzip = Nz(![fromzip])
strtozip = Nz(![tozip])
.
. route stuff
.
rstmilage.Edit
rstmilage("MPZipDist") = objRoute.Directions.Item(m).ElapsedDistance
rstmilage("Create_Time") = CalcTime
'**** add label so error handler knows where to return ****
SKIP_TO_NEXT:
'*************************************************
objRoute.Clear
rstmilage.Update
rstmilage.MoveNext
objRoute.Clear
Else
.
. else stuff here
.
End If
Loop
rstmilage.Close
End With
objApp.Quit
MsgBox "All Done"
'*********************************
'*** Add subroutine exit so sub does not
'*** fall into error code
'*********************************
Exit_:
Exit Sub
'********************************
'*** code that handles the error
'********************************
ProcessError:
'if the error number is equal to that generated when
'connectors not available
If Err.Number = "-2147221503" Then
'mark recordset for editing
rstmilage.Edit
'set values
rstmilage("MPZipDist") = "999999"
rstmilage("Create_Time") = CalcTime
'go to label
Resume SKIP_TO_NEXT
Else
'otherwise show error and exit
MsgBox "ERROR: " & Err.Number & vbCrLf _
& Err.Description & vbCrLf _
& "Module: Module1" & vbCrLf _
& "Subroutine: TestRoute" & vbCrLf & vbCrLf _
& "Exiting Now"
GoTo Exit_
End If
End Sub
|
![]() |
| Tags |
| calculation, error, handle, route |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
| ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Automate large list of drive time & distance calculation | onegalacticwino | MapPoint 2006/2009 Discussion | 1 | 12-13-2004 02:14 PM |
| Distance Calculation | jburgess | MapPoint 2006/2009 Discussion | 2 | 11-06-2004 09:33 PM |
| Fast Calculation of Driving Distance between 2 points | Bob Chase | Wish List | 6 | 08-19-2004 07:10 PM |
| hiding directions after route calculation in a MP controll | ruyasan | MapPoint 2006/2009 Discussion | 4 | 05-19-2004 06:19 PM |
| Is it possible to get a direct HANDLE to the Map? .... | Anonymous | MapPoint 2006/2009 Discussion | 2 | 06-19-2002 10:05 AM |