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
|
![]() |
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 01:14 PM |
| Distance Calculation | jburgess | MapPoint 2006/2009 Discussion | 2 | 11-06-2004 08:33 PM |
| Fast Calculation of Driving Distance between 2 points | Bob Chase | Wish List | 6 | 08-19-2004 06:10 PM |
| hiding directions after route calculation in a MP controll | ruyasan | MapPoint 2006/2009 Discussion | 4 | 05-19-2004 05:19 PM |
| Is it possible to get a direct HANDLE to the Map? .... | Anonymous | MapPoint 2006/2009 Discussion | 2 | 06-19-2002 09:05 AM |
Three Valleys France
The Three Valleys in France have a great reputation for great skiing. Holiday Hypermarket has just added another reason for you to go, a range of great prices from top travel operators.
Spain Weather
Check out Spain Weather - Travel Counsellors details information on Spain including, weather, flights and accommodation.
Holiday in Turkey
A Holiday in Turkey is great value when you book with dealchecker.co.uk. There is an abundance of things to see and do. Check out the well-preserved Greco-Roman ruins.
Cyprus Holidays
Cyprus holidays will offer you a wealth of activities all in the most beautiful surroundings. Relish the beauty of Cyprus on a short break.
Tunisia
Tunisia enjoys excellent weather, golden beaches and a beautiful blue sea. Moving away from the beach you will find a country that has a rich and varied past. Discover the secrets of history yourself by exploring all the ruins.
Cheap Holiday
For the holiday of your life that is cheap enough to afford with ease, visit Travel.co.uk
Holidays in Goa
Want to know more about Indian culture? Visit On The Beach for information on holidays in Goa.