View Full Version : How do you loop through the stops on a route?

01-02-2003, 10:56 AM
I need to associate the address to the stop number on the route so that I can then print a separate report, which would need to be in stop sequence order?

Is there a way to see what address has which stop number?

11-11-2003, 11:06 AM
If you're using the Mappoint Object model in your own APP:
Here's how I do it: (VB psuedocode)

'Declare and initialize a new Map
Dim MyMap As MapPoint.Map
Set MyMap = MPC.NewMap(geoMapNorthAmerica)

'Now Declare and initialize a Route on that map
Dim MyRoute As MapPoint.Route

'Tie the two things together. Now you've got a Route to work with
Set MyRoute = MyMap.ActiveRoute

'Now clear the Route

'You can now begin Adding WayPoints to your new clean Route
'A Waypoint consists of a Location and a Name
'I use a Ticket# - Description for the name of my waypoints

MyRoute.WayPoints.Add "Location Address...", "Ticket 12345 - Someplace"
'Keep adding waypoints till your done.

'Now your route is polulated with Waypoints, you can optimize and recalc

MyRoute.Waypoints.Optimize '...This could take a while...

MyRoute.Calculate 'This will create new driving directions

'Now your route contains a collection of waypoints in the optimized order.
'You can loop back through them.
'In this example, I have a table of Ticket #'s that I'm going to update with the optimized Order. Then I can just print the data from the table sorted in that order

'You need a counter. The waypoints are in ordinal position in an array

CountWaypoints = 1
Do While CountWaypoints < MyRoute.Waypoints.Count

'ThisTicket is a function that strips the Ticket# that's been embedded into the Name property for each waypoint.

StopTicket = ThisTicket(MyRoute.Waypoints.Item(CountWaypoints). Name)

'MarkRouteOrder is a subroutine that actually updates the Access table with the counter for the given Ticket#

MarkRouteOrder StopTicket, CountWaypoints

'Now move forward in the collection
CountWaypoints = CountWaypoints + 1


Done! You can now print your stuff from the table in the optimized order.

I would strongly suggest some sort of identifier on the items you want to sort (like I used Ticket #). Trying to update the table with some sort of matching on an address could be problematic.

As always, YMMV.