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 3 of 3

query shape produces wrong results

This is a discussion on query shape produces wrong results within the MapPoint Desktop Discussion forums, part of the Map Forums category; I am working on the following code to select pushpins graphically. I prefer not to send the data to Excel. ...

  1. #1
    David Kachuck is offline Junior Member Yellow Belt
    Join Date
    Jul 2002
    Posts
    17

    query shape produces wrong results

    I am working on the following code to select pushpins graphically. I prefer not to send the data to Excel. If someone sees what's wrong with my code, I would appreciate the correction. The number of pushpins selected is always all of the pushpins on the map.

    This is the code:

    Private Sub mnuSelectRectangle_Click()
    Dim intShapes As Integer
    Dim longHeight As Long
    Dim longWidth As Long
    Dim longTop As Long
    Dim longLeft As Long


    Set objMap = MappointControl1.ActiveMap

    longHeight = objMap.SelectedArea.Height
    longWidth = objMap.SelectedArea.Width
    longTop = objMap.SelectedArea.Top
    longLeft = objMap.SelectedArea.Left

    objMap.SelectedArea.SelectArea longTop, longLeft, longWidth, longHeight
    Set objLoc = objMap.SelectedArea.Location

    If longHeight = 0 Or longWidth = 0 Or longTop = 0 Or longLeft = 0 Then
    MsgBox "Nothing selected. "
    Exit Sub
    End If

    Set objShape = objMap.Shapes.AddShape(geoShapeRectangle, objLoc, CDbl(longWidth), CDbl(longHeight))
    objShape.Select

    MsgBox "The type of shape selected is " + CStr(objMap.Shapes.Item(1).Type)

    Set objDataSet = objMap.DataSets.Item(2)

    If objShape Is Nothing Then
    MsgBox "objShape got lost"
    End If

    Set objRecordset = objDataSet.QueryShape(objShape)

    ' Loop over records and place the captured pushpins in a list box

    objRecordset.MoveFirst
    intShapes = 0
    Do While Not objRecordset.EOF
    frmSelectAccounts.lstAccounts.AddItem objRecordset.Pushpin.Name
    objRecordset.MoveNext
    intShapes = intShapes + 1
    Loop

    MsgBox "Number of records in shape: " + CStr(intShapes)
    frmSelectAccounts.Show

    End Sub
    David Kachuck
    dk0146@netscape.net

    Oracle Certified Professional Database Administrator (OCP)
    MS Access Certified Expert (MAUS)

  2. #2
    John Meyer's Avatar
    John Meyer is offline Senior Member Blue Belt
    Join Date
    Jul 2002
    Posts
    478
    David,

    I think this sample I posted might help?
    Orignal post: http://www.mp2kmag.com/mappoint/disc...pic.asp?t=3327

    Give this a try, I think it will do what your asking. I'm just counting the number of pushpins in the selected area (the rectangle made when holding the left mouse button and dragging) but you could get there name/location or whatever you need.. BTW, If you did not select an area it will just exit sub.
    Code:
    Private Sub Command1_Click() 
    On Error GoTo error: 
    Dim objmap As MapPointctl.Map 
    Set objmap = MappointControl1.ActiveMap 
    
    Dim sa As MapPointctl.SelectedArea 
    Set sa = objmap.SelectedArea 
    
    Dim objDataSet As MapPointctl.DataSet 
    Dim objRecords As MapPointctl.Recordset 
    
    
    Dim objLocs(1 To 5) As MapPoint.Location 
    Set objLocs(1) = objmap.XYToLocation(sa.Left, sa.Top) 
    Set objLocs(2) = objmap.XYToLocation(sa.Left + sa.Width, sa.Top) 
    Set objLocs(3) = objmap.XYToLocation(sa.Left + sa.Width, sa.Top + sa.Height) 
    Set objLocs(4) = objmap.XYToLocation(sa.Left, sa.Top + sa.Height) 
    Set objLocs(5) = objmap.XYToLocation(sa.Left, sa.Top) 
    
    'Remove the comment from the next line to see the polygon being queried 
    'objmap.Shapes.AddPolyline objLocs 
    
    lngCount = 0 
    
    For Each objDataSet In objmap.DataSets 
    Set objRecords = objDataSet.QueryPolygon(objLocs) 
    objRecords.MoveFirst 
    Do While Not objRecords.EOF 
    lngCount = lngCount + 1 
    objRecords.MoveNext 
    Loop 
    Next 
    MsgBox "Number of records in polygon: " & lngCount 
    
    Exit Sub 
    error: 
    MsgBox Err.Description 
    End Sub

  3. #3
    David Kachuck is offline Junior Member Yellow Belt
    Join Date
    Jul 2002
    Posts
    17

    select pushpins graphically

    Thanks. That works. I don't really understand (yet) why my query shapes solution doesn't work, but hey, why blow against the wind?
    David Kachuck
    dk0146@netscape.net

    Oracle Certified Professional Database Administrator (OCP)
    MS Access Certified Expert (MAUS)

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Does an object reside in my Shape or Shape boundaries?
    By hotrdd in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 08-04-2005, 09:51 PM
  2. Linking access query results to MPC
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 0
    Last Post: 06-22-2004, 11:25 AM
  3. Query by shape / polygon
    By blackmap in forum MapPoint Desktop Discussion
    Replies: 7
    Last Post: 02-12-2003, 03:35 AM
  4. reverse geo coding, results wrong
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 2
    Last Post: 09-22-2002, 09:11 AM
  5. I have a J++ web application that produces reports....
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 11-17-2000, 06:39 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