Welcome to MapForums!

Register, sign in, or use Facebook Connect above to join in and participate in the forum.

When you are signed in, this message, the ads in this row, and the red-underlined link ads all go away.

Subscribe to receive our newsletter.
Subscribe Unsubscribe
Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Invalud PostCode issue with MapPoint 2002 with C++ ActiveX in the MFC

This is a discussion on Invalud PostCode issue with MapPoint 2002 with C++ ActiveX in the MFC within the Development forums, part of the MapPoint Desktop Discussion category; Hi there, Wondering if anyone can help me. Im using C++ MFC with MapPoint 2002. Im trying to calculate routes ...

  1. #1
    PieEater3142 is offline Junior Member White Belt
    Join Date
    Jan 2008
    Posts
    6

    Question Invalud PostCode issue with MapPoint 2002 with C++ ActiveX in the MFC

    Hi there,

    Wondering if anyone can help me.
    Im using C++ MFC with MapPoint 2002.
    Im trying to calculate routes between lots of different sites and find the shortest drive time between the sites and certian buildings.
    I have a fairly stable program working at the moment, however i've got to running through some test data and the program is stopping when a post code does not exist in MapPoint.
    The AFX error message that comes up is:
    'The requested member of the collection does not exist. Use a valid name or index number.'

    I have no problem with there not being a post code match, however i need the program to keep running, and some way to tell the user which post code is not matched.

    Any ideas with this would be a great help.

    Cheers

    PieEater3142

  2. #2
    Eric Frost's Avatar
    Eric Frost is offline Administrator Black Belt
    Join Date
    Jul 1992
    Posts
    5,094
    Blog Entries
    4

    Re: Invalud PostCode issue with MapPoint 2002 with C++ ActiveX in the MFC

    Can you post your code snippet? I assume at one point you have a FindResults collection and you normally just take the first item in the collection? Can you check the number of objects or count of objects in the collection first?

    Eric
    ~ Order MapPoint MapPoint 2013 Here and Get Free Access to the MapForums Downloads ~
    ~~
    ~ Upgrade to Get Access to the MapForums Downloads ~

  3. #3
    PieEater3142 is offline Junior Member White Belt
    Join Date
    Jan 2008
    Posts
    6

    Re: Invalud PostCode issue with MapPoint 2002 with C++ ActiveX in the MFC

    Hi Eric,

    Cheers for the quick response:

    The function thats throwing the error is:
    bool Route_Calculator::calculate_route(CString patient_pc, CString site_pc)
    {
    //reset response value
    routeOK = false;

    //clear route information, ready for new route info
    m_Route.Clear();
    //clear distance and drivetime variables
    dblDistance=(double)0;
    dblDriveTime=(double)0;

    //MapPoint requires a variant type for passing the country
    //so Variant type created with value 242 - this is the UK
    VARIANT vtGeoCountry;
    vtGeoCountry.vt = VT_I4;
    vtGeoCountry.intVal = 242;

    //find postcodes on map
    CFindResults patient_loc = m_Map.FindAddressResults("", "", "", "", patient_pc, vtGeoCountry);
    CFindResults site_loc = m_Map.FindAddressResults("", "", "", "", site_pc, vtGeoCountry);

    //bodge factor to get around crappy microsoft product
    //create variant to pass with value 1 coz it cant handle an int
    VARIANT v2;
    v2.vt = VT_I4;
    v2.intVal = 1;

    //save the locations found to type CLocation for MapPoint to process
    CLocation p_lc = patient_loc.GetItem(&v2);
    CLocation s_lc = site_loc.GetItem(&v2);

    //add points to map
    m_WayPoints.Add(p_lc, "patient");
    m_WayPoints.Add(s_lc, "site");

    //calculate the best route
    m_Route.Calculate();

    //save distance and drive time to variables
    dblDistance = m_Route.GetDistance();
    dblDriveTime = m_Route.GetDrivingTime();

    if(dblDriveTime==0){
    routeOK = false;
    }else{
    routeOK = true;
    }

    return routeOK;
    }
    It uses the standard MapPoint classes built when you import the ActiveX control.

    It creates the error message when it gets one of the two following commands (depending which has the bad post code in):

    //save the locations found to type CLocation for MapPoint to process
    CLocation p_lc = patient_loc.GetItem(&v2);
    CLocation s_lc = site_loc.GetItem(&v2);

    Cheers for your help

    PieEater

  4. #4
    Eric Frost's Avatar
    Eric Frost is offline Administrator Black Belt
    Join Date
    Jul 1992
    Posts
    5,094
    Blog Entries
    4

    Re: Invalud PostCode issue with MapPoint 2002 with C++ ActiveX in the MFC

    Yes, I think it makes sense. You would be trying to get item 1 from a collection with no objects.

    Check the FindResults collection object in the Help File. It has five properties

    Properties
    Application
    Count
    Item*
    Parent
    ResultsQuality

    Before you use the GetItem, I think you want to check the Count property first to see if the collection has any items.

    hope that helps.
    Eric
    ~ Order MapPoint MapPoint 2013 Here and Get Free Access to the MapForums Downloads ~
    ~~
    ~ Upgrade to Get Access to the MapForums Downloads ~

  5. #5
    PieEater3142 is offline Junior Member White Belt
    Join Date
    Jan 2008
    Posts
    6

    Re: Invalud PostCode issue with MapPoint 2002 with C++ ActiveX in the MFC

    Hi Eric,

    Thanks for your help.
    Works like a charm.

    Where is this help file of which you speak.
    Im currently using the object browser in VB6 or looking at the Class view in C++ for the different functions.

    Thanks again.

    PieEater

  6. #6
    Eric Frost's Avatar
    Eric Frost is offline Administrator Black Belt
    Join Date
    Jul 1992
    Posts
    5,094
    Blog Entries
    4

    Re: Invalud PostCode issue with MapPoint 2002 with C++ ActiveX in the MFC

    Hello PieEater.

    Of what pie do you like the most?

    Under Start | Programs you may see MapPoint listed as a program, then go to Help and the Programming Information is at the bottom of the file.

    If you don't see MapPoint in the Start menu, then you should be able to find it by going to your \Program Files\ directory and look for Microsoft MapPoint, the help file is a "MAPPOINT.chm" file you should be able to just double-click on to open. As a last resort you could search your hard drive for MapPoint.chm. If you still don't find it let me know and I can send you a copy - I don't think I have the MapPoint 2002 chm file, but the API / object model should be just about identical to the MapPoint 2004 object model.

    Eric
    ~ Order MapPoint MapPoint 2013 Here and Get Free Access to the MapForums Downloads ~
    ~~
    ~ Upgrade to Get Access to the MapForums Downloads ~

  7. #7
    PieEater3142 is offline Junior Member White Belt
    Join Date
    Jan 2008
    Posts
    6

    Re: Invalud PostCode issue with MapPoint 2002 with C++ ActiveX in the MFC

    Hi Eric,

    Thanks for help file info.

    All pies are good - so many to choose from - but cant go wrong with chicken and mushroom or an apple pie

    Another question for you if you dont mind.

    I need to determine if a post code is on the isle of wight or not.

    Now from the help file this would be the map.FindAddressResults function.
    However the output is of type CFindResults for C++.
    From the help file:
    object.FindAddressResults([Street], [City], [OtherCity], [Region], [PostalCode], [Country])

    So the value should come back in the OtherCity or Region field.
    However how do i get the answer out in C++ - is there any way?

    Cheers again

    PieEater

  8. #8
    PieEater3142 is offline Junior Member White Belt
    Join Date
    Jan 2008
    Posts
    6

    Re: Invalud PostCode issue with MapPoint 2002 with C++ ActiveX in the MFC

    object.FindAddressResults([Street], [City], [OtherCity], [Region], [PostalCode], [Country])
    Think i've got the wrong function there - was trying to get something together in vb just to see whats what (still needs to be done in c++) and it doesnt appear to give the output.

    Any ideas what function can do what i need and how you can interpret the outputs?

    Cheers

    PieEater

  9. #9
    Eric Frost's Avatar
    Eric Frost is offline Administrator Black Belt
    Join Date
    Jul 1992
    Posts
    5,094
    Blog Entries
    4

    Re: Invalud PostCode issue with MapPoint 2002 with C++ ActiveX in the MFC

    Yes, you're right.

    Honestly I think the easiest thing and the most reliable would be if you know the postcode range - is it consistent? for instance if all postcodes in the Isle of Wight began with

    K3x xxxx through K8xx xxx or whatever

    and you could just test through some string functions.

    Eric
    ~ Order MapPoint MapPoint 2013 Here and Get Free Access to the MapForums Downloads ~
    ~~
    ~ Upgrade to Get Access to the MapForums Downloads ~

  10. #10
    PieEater3142 is offline Junior Member White Belt
    Join Date
    Jan 2008
    Posts
    6

    Re: Invalud PostCode issue with MapPoint 2002 with C++ ActiveX in the MFC

    Damn, ok thanks for that.
    Thought it might come to that but was looking for a neater way.
    Oh well.

    Cheers

    Yet another question - bit random but here we go:

    I have to use mappoint 2002 as its the only version that integrates with Visual C++ 6.
    Unfortunately the post codes are out of date.
    Is there any way to overwrite the data files on the mappoint 2002 version with the 2006 version for instance. I have tried - all file names are the same - sizes are obviously different but it doesnt work.
    Is it possible (by giving it some other files) or am i stuck with it.

    Thanks again for all your help with this, you've been a star.

    Cheers

    PieEater

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Mappoint Installation issue
    By jacky3212 in forum MP2K Magazine Articles
    Replies: 2
    Last Post: 07-19-2008, 12:08 AM
  2. MapPoint 2002 ActiveX control and Visual Studio .NET 2003
    By chulaka in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 09-30-2003, 10:35 AM
  3. GetName() problem in 2002 ActiveX in VC++
    By jvirtue in forum MapPoint Desktop Discussion
    Replies: 0
    Last Post: 09-26-2003, 01:04 PM
  4. Map Point 2002 Europe Postcode Sector Updates
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 10-08-2002, 10:13 AM
  5. I am using Mappoint 2002 ActiveX control in a VB a....
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 2
    Last Post: 06-14-2002, 07:10 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87