Please. Help me understand this code

  • Thread starter Thread starter Viper
  • Start date Start date
V

Viper

Hello a guy in the MapPoint forum sent me this code and said this is
the way to get it done in C#
But i need it in access code

I dont know c# at all

Can anyone explain how to interpret this code?


FindResults results = MP.ActiveMap.FindAddressResults(street, city, "",
"", zip, "");
if (results.ResultsQuality ==
GeoFindResultsQuality.geoFirstResultGood) {
Route route = MP.ActiveMap.ActiveRoute;
route.Clear();

// set first point
object o = 1;
Location loc = (Location)results.get_Item(ref o);
Waypoint wp = route.Waypoints.Add(loc, loc.Name);
wp.SegmentPreferences = GeoSegmentPreferences.geoSegmentPreferred;

results = MP.ActiveMap.FindAddressResults(street2, city2, "", "",
zip2, "");
if (results.ResultsQuality ==
GeoFindResultsQuality.geoFirstResultGood) {
// set last point
o = 1;
loc = (Location)results.get_Item(ref o);
wp = route.Waypoints.Add(loc, loc.Name);
wp.SegmentPreferences = GeoSegmentPreferences.geoSegmentPreferred;

// set preferred roads

route.DriverProfile.set_PreferredRoads(GeoRoadType.geoRoadArterial,
0.1);
route.DriverProfile.set_PreferredRoads(GeoRoadType.geoRoadFerry,
0.1);

route.DriverProfile.set_PreferredRoads(GeoRoadType.geoRoadInterstate,
0.9);

route.DriverProfile.set_PreferredRoads(GeoRoadType.geoRoadOtherHighway,
0.6);
route.DriverProfile.set_PreferredRoads(GeoRoadType.geoRoadToll,
0.2);

// set preferred speeds
route.DriverProfile.set_Speed(GeoRoadType.geoRoadArterial, 50);
route.DriverProfile.set_Speed(GeoRoadType.geoRoadInterstate, 120);
route.DriverProfile.set_Speed(GeoRoadType.geoRoadLimitedAccess,
120);
route.DriverProfile.set_Speed(GeoRoadType.geoRoadOtherHighway,
90);
route.DriverProfile.set_Speed(GeoRoadType.geoRoadStreet, 50);

route.DriverProfile.StartTime = System.DateTime.Now;
route.Calculate();

Console.WriteLine("Minutes " + route.TripTime * 1440);
 
Hi Viper,

Syntax like this in C#
Long myNumber = 99;
translates to VBA as
Dim MyNumber As Long
MyNumber = 99

so
FindResults results = MP.ActiveMap.FindAddressResults(street,
city, "", "", zip, "");
probably means
Dim results As FindResults
Set results = MP.ActiveMap.FindAddressResults( _
street, city, "", "", zip, "")

And
if (something == somethingelse) {
...
}
translates as
If something = somethingelse Then
...
End If
 
Thank you so very much

I couldn't make sense of that long my number

But, now that you point it out it makes a lot more sense

Thanks a lot

I think i can get it to work now
 
I cannot get this to work

Here is what i have so far Does it look correct

I simply have a text box i am trying to put the drive time into for
now


Private Sub Command2_Click()
'Define variables to hold our information.
Dim oApp As Object, omap As Object
Dim oPush(1 To 2) As Object
Dim oloc As Object
Dim oLOCtwo As Object

Set oApp = CreateObject("Mappoint.Application")
Set omap = oApp.NewMap 'Create a new map

Set oloc = omap.Find("247 davis road" & " , " & Dawson & " , " &
PA & ", " & 15428) 'Geocode the first address
If Not oloc Is Nothing Then 'Check to see if the first
address was found.
Set oPush(1) = omap.AddPushpin(oloc) 'Place a pushpin on the
map
oPush(1).GoTo 'Go to that pushpin

Set oLOCtwo = omap.Find("1801 Trenton Ct" & " , " & "Cranberry
Twp" & " , " & PA & " , " & 16066) 'Geocode the second address
If Not oLOCtwo Is Nothing Then 'Check to see if the second
address was found
Set oPush(2) = omap.AddPushpin(oLOCtwo) 'Add a pushpin for it
oPush(2).Highlight = True

With omap.ActiveRoute 'Let's generate some
directions between the points
omap.Waypoints.Add oloc 'Add the first address
omap.Waypoints.Add oLOCtwo 'Add the second address
omap.ActiveRoute.Calculate 'Now find the
directions between them
End With

Me.Text0 = Console.WriteLine("Minutes " + omap.ActiveRoute.TripTime *
1440)

Else 'If the second location is not found, then
indicate no directions
Me.Text0.SetFocus
Me.Text0.text = "No second location found!"
End If


Set omap = Nothing
Set oApp = Nothing
End If
End Sub
 
I would expect it should be:

Set oloc = omap.Find("247 davis road, Dawson, PA, 15428")

since you don't have variables named Dawson, PA or 15428.

Similarly, it should probably be

Set oLOCtwo = omap.Find("1801 Trenton Ct, Cranberry Twp, PA, 16066")

Since the original code was C#, it does a reference to Console.WriteLine
that won't work in VBA. That should probably be

Me.Text0 = "Minutes " + omap.ActiveRoute.TripTime * 1440
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top