MapPoint Forums

MapForums

Community of VE/MapPoint Users and Developers




building an optimal route using VBA

This is a discussion on building an optimal route using VBA within the MapPoint 2006/2009 Discussion forums, part of the Map Forums category; I'm building an Excel model which has a VBA module which needs to read in a set of locations (lat/long ...


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

Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read



Click here to register

Reply

 

LinkBack (5) Thread Tools Display Modes
  5 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 07-20-2007
Junior Member
White Belt
 
Join Date: Jan 2004
Posts: 5
building an optimal route using VBA

I'm building an Excel model which has a VBA module which needs to read in a set of locations (lat/long data) from Excel and find an optimal route around the points - as if you were using the "optimize stops" button in MapPoint.

Could anyone help me with the code?

I know how to add in individual pushpins using VBA code but not a large set of points (say 150) to add to the route.

Version is MP2002 Europe
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 07-20-2007
Junior Member
White Belt
 
Join Date: Jan 2004
Posts: 5
Re: building an optimal route using VBA

okay, I've sussed out how to read the points in

now I just need to optimise the stops

my current line of code is: (oRoute is my MapPoint.Route object)

oRoute.Calculate

but I need something which will not just find the route as they were inputted but the optimal order.
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 07-20-2007
Eric Frost's Avatar
Senior Member
Black Belt
 
Join Date: Jul 1992
Posts: 2,470
Blog Entries: 1
Re: building an optimal route using VBA

Maybe it's a little non-intuitive, but the Optimize method is a method of the WayPoints collection, not the Route like you might think.

Check out the help file

WayPoints is a property of the Route object.

WayPoints itself is a Collection.

WayPoints has the Optimize method and an IsOptimized property.

Here is the description and code sample for the Optimize method from the Help file (actually copied from the MapPoint 2004 help file so it might be a little different from yours).

Optimize method

Reorders the intermediate stops on a route so that the travel time between the start and end points is the most efficient; similar to clicking Optimize Stops on the Route menu.

Applies to
Collections: Waypoints

Syntax
object.Optimize

Part Description
object Required. An expression that returns a Waypoints collection.

Remarks

The RouteAfterOptimize event of the Map or MappointControl object occurs after the stops on the route have been optimized.

After stops are optimized, the route no longer exists on the map. Be sure to use the Calculate method on the Route object.

For more information about optimizing the stops on a route, see the Optimize the stops on your route procedural topic.

Example

Code:
 
  Sub OptimizeRoute()
  Dim objApp As New MapPoint.Application
  Dim objMap As MapPoint.Map
  Dim objRoute As MapPoint.Route
  'Set up the application
  Set objMap = objApp.ActiveMap
  Set objRoute = objMap.ActiveRoute
  objApp.Visible = True
  objApp.UserControl = True
  'Add route stops and calculate route
  With objRoute.Waypoints
    .Add objMap.FindResults("Seattle, WA").Item(1)
    .Add objMap.FindResults("Redmond, WA").Item(1)
    .Add objMap.FindResults("Tacoma, WA").Item(1)
    .Add objMap.FindResults("Bellevue, WA").Item(1)
  End With
  objRoute.Calculate
  'Optimize the route
  objRoute.Waypoints.Optimize
  End
SubNote This sample code is specific for use in MapPoint North America; it is for illustration purposes only.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4 (permalink)  
Old 07-20-2007
Junior Member
White Belt
 
Join Date: Jan 2004
Posts: 5
Re: building an optimal route using VBA

thanks for that Eric. I'll give it a go

I actually tried

oRoute.Waypoints.Optimize = true

but it spat that out
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5 (permalink)  
Old 07-20-2007
Eric Frost's Avatar
Senior Member
Black Belt
 
Join Date: Jul 1992
Posts: 2,470
Blog Entries: 1
Re: building an optimal route using VBA

It's a method with no parameters, I don't think you need to say anything, just do

.Optimize

not

.Optimize = Tue

best,
Eric
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

Tags
building, optimal, route, vba


LinkBacks (?)
LinkBack to this Thread: http://www.mapforums.com/building-optimal-route-using-vba-6089.html

Posted By For Type Date
Using MapPoint and Excel for Supply Chain Management - MapPoint Articles - MP2K Magazine This thread Refback 07-28-2007 11:22 PM
Working With Excel and MapPoint - MP2K Magazine This thread Refback 07-28-2007 02:49 AM
Home Locator Sample Application - MapPoint Articles - MP2K Magazine This thread Refback 07-25-2007 02:05 PM
The Magazine for MapPoint - MP2K Magazine This thread Refback 07-21-2007 07:19 AM
Map Visitors - Powered by Virtual Earth This thread Refback 07-20-2007 11:41 AM

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
Building a GIS using mappoint technology vishwadev MapPoint Web Service and Virtual Earth 10 06-06-2007 02:06 PM
MapPoint Road building tool larrya Wish List 1 04-03-2005 10:46 PM
How do you map optimal route for multiple pick up addresses? mprdj MapPoint 2006/2009 Discussion 0 11-15-2004 02:30 PM
Is the Optimal stop Function optimal????? Anonymous MapPoint 2006/2009 Discussion 0 06-13-2004 11:34 AM
How do we add our building (Shape) data to MapPoi.... Anonymous MapPoint 2006/2009 Discussion 1 08-06-2001 10:32 AM


All times are GMT -5. The time now is 10:14 AM.


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


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 52 53 54