Community of VE/MapPoint Users and Developers
This is a discussion on On Error Help - VBA within the Development forums, part of the MapPoint 2006/2009 Discussion category; ok, so I'm writing VBA code for an excel spreadsheet and Mappoint 2004, that returns the road distance between two ...
| |||||||
| Register | Blogs | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| |||
| On Error Help - VBA 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 Last edited by andriy; 10-04-2007 at 11:25 AM. Reason: remove unneccesary personal comments |
| |||
| Re: On Error Help - VBA
Hi, the line of code where you open the map is put in comment.
__________________ rgds, Wilfried Mestdagh www.mestdagh.biz MapPoint coding demo Order MapPoint 2009 with Routing and User Tools Spreadsheet |
| |||
| Re: On Error Help - VBA
That's because I don't want to open a map, just the application, so that it calculates a distance for me... I should have removed that... (Please, correct me if I'm wrong) It runs fine, when you have road accessible zip codes, but trying to measure the road distance from Hawai to LA, returns an error... an obvious one, at that, but how to put it into VBA Mappoint language? Are there error numbers in mappoint, just like in excel? thanks, andriy |
| |||
| Re: On Error Help - VBA
Hi, If you uncomment the line then same problem ? To debug you can step with the debugger trough the code to find the offending line. Also you can put the whole thing in an exception block, then probably more error information. How to do both I don't know, I don't know VBA, but sure others can jump in here.
__________________ rgds, Wilfried Mestdagh www.mestdagh.biz MapPoint coding demo Order MapPoint 2009 with Routing and User Tools Spreadsheet |
| ||||
| Re: On Error Help - VBA
Yep MapPoint throws an exception if it cannot find a route - eg. locations on different islands, poor farm roads, etc. You need to trap the exception and "do something appropriate" (eg. ignore it, write a " " for the distance, or whatever is appropriate for you) Use "ON ERROR" to trap exceptions in VB6. Richard
__________________ Winwaed Software Technology LLC http://www.winwaed.com See http://www.mapping-tools.com for MapPoint Tools Pre-Order MapPoint 2009 today: http://www.mapping-tools.com/mappoint2009 |
| |||
| Re: On Error Help - VBA
For those that want to test this out on your computers: open up excel, pop in the following into the Excel's VB Editor... >>>>>>>>>>>>>>>>>>> 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 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 >>>>>>>>>>>>>>>>>>> make sure to check your references in the VB Editor, and click on Mappoint Library... now on a sheet in A1, enter 53.62 A2 = -88.68 B1 = 46.53 B2 = -84.36 C1 = RoadDistance(A1, A2, B1, B2) and see what happens... hope this helps... andriy |
| |||
| Re: On Error Help - VBA
Hi, Can you also tell what happens ? (not everyone has Excel or know how to use the VB thing) Did you try the exception block as Richard proposed ?
__________________ rgds, Wilfried Mestdagh www.mestdagh.biz MapPoint coding demo Order MapPoint 2009 with Routing and User Tools Spreadsheet |
| |||
| Re: On Error Help - VBA
so I made this minor correction, and have the On error statement before the questionable piece of code... yay the program runs... so for those following the code on your own computers, it should read: ... SysRoute.Waypoints.Add SysLoc2 On Error GoTo IsolatedPC SysRoute.Calculate RoadDistance = SysRoute.Distance SysRoute.Clear ... thanks for your help I still think Mappoint shoud do this automatically, or have a flight option built in, where you take an alternative means of transport, for as short of time as possible... then travel by roads... regards, andriy |
![]() |
| ||||
| Posted By | For | Type | Date | |
| Converting Strings Into Decimal Degree Format - MapPoint Articles - MP2K Magazine | This thread | Refback | 10-10-2007 07:38 AM | |
| pushpin and route calculator | This thread | Trackback | 10-09-2007 11:07 AM | |
| Reverse Geocoding with MapPoint 2002 - MapPoint Articles - MP2K Magazine | This thread | Refback | 10-09-2007 08:49 AM | |
| Reverse Geocoding, Another Method - MapPoint Articles - MP2K Magazine | This thread | Refback | 10-08-2007 10:11 AM | |
| The Magazine for MapPoint - MP2K Magazine | This thread | Refback | 10-07-2007 05:34 AM | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
| ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Run-time error 2147467259 80004005 automation error | ThomasB | MapPoint 2006/2009 Discussion | 2 | 02-27-2007 11:41 AM |
| Error using MP 2006 | PC7395 | MapPoint 2006/2009 Discussion | 7 | 08-28-2006 04:43 PM |
| About ERROR 4-40028-1. Error or Bug ? | Anonymous | MapPoint 2006/2009 Discussion | 12 | 01-11-2005 09:32 AM |
| I get this following error | ananthdeena | MapPoint 2006/2009 Discussion | 3 | 01-01-2005 02:46 AM |
Cheap Flight to Tenerife
Get a cheap flight to Tenerife and a cheap hotel in Tenerife giving you a great value holiday in Tenerife. Holiday Hypermarket can make it happen.
City Break Europe
Take a city break in Europe. Travel Counsellors can help plan and book your European city break.
Jamaica Holiday
Fancy a Jamaica Holiday? Then visit dealchecker.co.uk and find out what the big deal is. Book a bargain when you book online.
Holidays in Dubai
Holidays in Dubai are an eclectic mix of the ancient and the modern. Discover an oasis of luxury amid the Arabian desert. Book here now!
Cheap Morocco Holidays
Cheap Morocco holidays may be the answer to your cheap holiday search. With sunshine throughout most of the year it can be great value if you avoid the peak season. Why not include a trip to the small tranquil town of Chefchaouen Tangier in your visit?
Holidays Package
Make use of our service at Travel.co.uk to compare holidays. We can find you a package deal that will delight you.
Portugal Holidays
We specialise in Portugal holidays. Visit our On The Beach website for more information.