MapPoint Forums

MapForums

Community of VE/MapPoint Users and Developers




How to handle route calculation error

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 ...


Go Back   MapPoint Forums > Map Forums > MapPoint 2006/2009 Discussion

Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-16-2003
Junior Member
White Belt
 
Join Date: Nov 2003
Posts: 2
How to handle route calculation error

Hi all.

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 12-16-2003
Junior Member
Yellow Belt
 
Join Date: Feb 2003
Posts: 28
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 12-17-2003
Junior Member
White Belt
 
Join Date: Nov 2003
Posts: 2
Thank you for your help. Code worked like a champ!

Rolf
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

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


All times are GMT -5. The time now is 01:09 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
MP2K Magazine
Visitor Map

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.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51