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
Results 1 to 9 of 9

Bizarre solution to a QueryShape problem...

This is a discussion on Bizarre solution to a QueryShape problem... within the MapPoint Desktop Discussion forums, part of the Map Forums category; Hi All, I've been having a bit of a nightmare problem with QueryShape (MP2006 European Maps & VB.NET)! I have ...

  1. #1
    jlewis is offline Member Yellow Belt
    Join Date
    Apr 2006
    Posts
    33

    Bizarre solution to a QueryShape problem...

    Hi All,

    I've been having a bit of a nightmare problem with QueryShape (MP2006 European Maps & VB.NET)!

    I have a map (.ptm) with about 400 shapes on it. I have one pushpin and I need to see which shapes (if any) that pushpin is inside.

    So - I'm iterating through the each shape and doing a QueryShape and doing something if the puhpin IS inside the shape.

    The problem is that it goes through all the shapes and then, when I do Application.Quit MapPoint crashes (with a 'MapPoint has encountered an error and needs to close').

    Various tests have shown that it gets through a bunch of shapes (almost always 202) then fails on a bunch then completes the remainder.

    I inadvertantly found a solution (I think!).

    Here's my code:-

    Code:
     
    For Each Shp In lApp.ActiveMap.Shapes
      shpct += 1
      Try
        oRecords = oDataSet.QueryShape(Shp)
        oRecords.MoveFirst()
        Do While Not oRecords.EOF
          'Do something....
          oRecords.MoveNext()
        Loop
      Catch ex As Exception
        txtShapeInfo.Text &= ControlChars.CrLf & shpct & "  " & Shp.Name & " !!!! NOT OK !!!!"
      End Try
    Next
    lApp.Quit()
    This chucks a load of stuff into txtInfoShape.Text (the exception is an 'Unspecified Error') and then bombs out!

    By accident, I found that if I do the following :-

    Code:
     
    For Each Shp In lApp.ActiveMap.Shapes
      shpct += 1
      Try
        oRecords = oDataSet.QueryShape(Shp)
        oRecords.MoveFirst()
        Do While Not oRecords.EOF
          'Do something....
          oRecords.MoveNext()
        Loop
        txtShapeInfo.Text &= ControlChars.CrLf & shpct & "  " & Shp.Name & " OK"
      Catch ex As Exception
        txtShapeInfo.Text &= ControlChars.CrLf & shpct & "  " & Shp.Name & " !!!! NOT OK !!!!"
      End Try
    Next
    lApp.Quit()
    The exception isn't thrown and everything works fine! The line in red doesn't need to be the same textbox as the one in blue - but it must be visible!

    Am I going mad or is there a reasonable explanation for this?
    John Lewis

  2. #2
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    2,433

    Re: Bizarre solution to a QueryShape problem...

    Hi,

    The only thing a textbox do is pumping messages. How long does it take to execute the loops ? and are you executing it from within one of the events from mappoint ?

  3. #3
    jlewis is offline Member Yellow Belt
    Join Date
    Apr 2006
    Posts
    33

    Re: Bizarre solution to a QueryShape problem...

    Hi Wilfried,

    Thanks for the reply.

    It takes about 6 seconds to query 479 shapes (on my machine - Core 2, 2GHz with 2 Gig RAM).

    I'm not doing it from within a MapPoint event.

    Could it be that the COM object is being overwhelmed and the pumping to the textbox gives it a chance to have a breather and catch up with itself?
    John Lewis

  4. #4
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    2,433

    Re: Bizarre solution to a QueryShape problem...

    Hi,

    If you are not calling the loop direct or indirect from an event I don't see a reason. Maybe mappoint is try to call an event, but still it should work. Strange thing is that it is after a certain amount of queries.

    As an alternative you could try to pump in the loop by calling the win32 API function PeekMessage and see what it does. Eventually try the 2 options that is removing the message and don't remove it.

    Furthermore I'm a little out of ideas for this

  5. #5
    nickhoare is offline NickH Yellow Belt
    Join Date
    Jun 2008
    Location
    Bromsgrove, UK
    Posts
    24

    Re: Bizarre solution to a QueryShape problem...

    I am having exactly the same problem in MP2004. After querying about 137 shapes the Unspecified Error exception is thrown. If I persist then after a few errors it continues again Then after about another 137 I get the error again. I have added a "Completed x" message on a Status strip and now it runs to 179 before getting the error. It looks like if I allow more time (somehow) it will work its way all the way through.

  6. #6
    nickhoare is offline NickH Yellow Belt
    Join Date
    Jun 2008
    Location
    Bromsgrove, UK
    Posts
    24

    Re: Bizarre solution to a QueryShape problem...

    I have since found that an Application.Doevents after every call to Queryshape seems to fix the problem. I only have 200 or so shapes at the moment.

  7. #7
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    2,433

    Re: Bizarre solution to a QueryShape problem...

    Hi,

    Thank you for feedback. Indeed pumping messages (GetMessage, PeekMessage, DoEvents) can be the solution. Be aware that if you execute the message pump that your code can be re-entered depending the flow of the application.

  8. #8
    nickhoare is offline NickH Yellow Belt
    Join Date
    Jun 2008
    Location
    Bromsgrove, UK
    Posts
    24

    Re: Bizarre solution to a QueryShape problem...

    I have found that Doevents does not work 100% of the time. I am unfamiliar with GetMessage/PeekMessage so don't know if their use would be better.

  9. #9
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    2,433

    Re: Bizarre solution to a QueryShape problem...

    Hi,

    Should be the same. As far as I know DoEvents is just a P/Invoke to the Win32 functions to pump messages. If not some dotnet expert can correct me.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. QueryShape or QueryPolygon NOT IN
    By tfmiltz in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 01-31-2008, 09:03 AM
  2. QueryShape recordset returning empty
    By tfmiltz in forum MapPoint Desktop Discussion
    Replies: 7
    Last Post: 01-31-2008, 07:38 AM
  3. problems with queryshape
    By chas in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 09-08-2006, 02:52 PM
  4. Problem with dataset.QueryShape Method
    By Ray Liu in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 07-15-2004, 11:55 AM
  5. QueryShape problem Please help
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 2
    Last Post: 03-13-2003, 09:57 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