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

Order a recordset?

This is a discussion on Order a recordset? within the MapPoint Desktop Discussion forums, part of the Map Forums category; I'm hoping someone can help me modify this code. The code below loops through a Microsoft MapPoint recordset, and assigns ...

  1. #1
    Shecky is offline Junior Member White Belt
    Join Date
    Oct 2004

    Order a recordset?

    I'm hoping someone can help me modify this code. The code below loops through a Microsoft MapPoint recordset, and assigns a sequentially numbered Pushpin symbol to each record in the recordset. This code works perfectly fine, except that the recordset is not in the proper order that I need, and there doesn't seem to be a method available to sort the recordset object. I need my recordset to be ordered according to this field: objRS.Fields(24).Value

    Is there a way that I can loop through the recordset to find the lowest value for "objRS2.Fields(24).Value", then assign the numbered pushpin symbol, then loop through the recordset again to find the next lowest value in that same field and then assign the next numbered pushpin symbol. I guess the structure that makes the most sense to me would be some sort of nested loop, but I can't seem to figure out how to structure it. Thanks so much.

    Dim objRS As MapPoint.Recordset
    Dim objDataSet As MapPoint.DataSet

    Set objRS = objDataSet.QueryAllRecords
    Set objDataSet = objApp.ActiveMap.DataSets.Item(2)

    intSymbol = 208

    Do Until objRS.EOF
    objRS.Pushpin.Symbol = intSymbol
    intSymbol = intSymbol + 1
    Lead, follow, or get out of the way!

  2. #2
    Eric Frost's Avatar
    Eric Frost is offline Administrator Black Belt
    Join Date
    Jul 1992
    Blog Entries
    Hi Shecky,

    First try to distill it down to a more basic programming problem, don't complicate things with MapPoint. Are there ever any records with the same value?

    Try Google for "shell sort", this looks like one of the more basic algorithms:

    good luck,

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

  3. #3
    Shecky is offline Junior Member White Belt
    Join Date
    Oct 2004
    Thanks for the input. I'm a fairly novice programmer, so that's why I didn't appreciate the complexity of what I was posting. I'll look at your suggestion and post back.
    Lead, follow, or get out of the way!

  4. #4
    Winwaed's Avatar
    Winwaed is offline Mapping-Tools.com Black Belt
    Join Date
    Feb 2004
    Blog Entries

    By spooky coincidence I was after something very similar in the past hour or so. A RecordSet.SortOnName() would have been ideal for what I wanted but no such method exists. Therefore I had to sort the values after I have read them from the RecordSet.
    As a quick bit of coding, I wrote the following Bubble Sort:

    Public Sub Sort(strKeys() As String, dat() As MapPoint.Location, n As Long)
        ' Crude Bubble Sort
        ' This should be replaced with a QuickSort at a future date
        Dim i As Integer
        Dim j As Integer
        Dim swapString As String
        Dim swapLoc As MapPoint.Location
        For i = 1 To n - 1
            For j = i + 1 To n
                If (strKeys(i) > strKeys(j)) Then
                    swapString = strKeys(i)
                    strKeys(i) = strKeys(j)
                    strKeys(j) = swapString
                    Set swapLoc = dat(i)
                    Set dat(i) = dat(j)
                    Set dat(j) = swapLoc
                End If
           Next j
        Next i
    End Sub
    The strKeys and dat arrays have indices 1..n (yes I know this can be generalised). The Location objects in 'dat' are sorted in alphabetical order according to the names in 'strKeys'

    Visual Basic isn't my native tongue as it were, so I was more than happy to get something like the above running, and then to replace it with a better type of sort later.

    Looking at the page that Eric has linked to... Eric, I'm pretty certain that that is a "QuickSort" rather than a "Shell Sort"! Just what I'm after
    I have a copy of the Pascal version of 'Sedgwick' here - and it looks like his recursive implementation.

    Shecky: If this is all new to you, then you probably won't know what all these sorts are. "BubbleSort" (ie. my code) is usually the first one mentioned in beginner programming texts. It is easy to understand and quick to write. However it is notoriously slow. Basically it works its way through finding the last object, then the next-to-last, etc. As each object is found it "bubbles" to the correct location by a long line of data swaps.
    "Shell Sort" is meant to be a bit faster, and QuickSort is generally a lot faster (although the worst case can be fairly slow).
    Speed is heavily dependent on the size of the data. Eg. if you're only sorting 10 items, BubbleSort is probably fast enough!

    Winwaed Software Technology LLC
    See http://www.mapping-tools.com for MapPoint Tools

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. PushPin and Line Order
    By stevet in forum MapPoint Desktop Discussion
    Replies: 2
    Last Post: 06-19-2006, 01:37 PM
  2. Pushpin Z Order
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 0
    Last Post: 09-06-2004, 06:00 PM
  3. How is possible to force order in Recordset?
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 0
    Last Post: 08-27-2004, 04:06 AM
  4. Order/Sort Recordset with pushpins ???
    By Michelin in forum MapPoint Desktop Discussion
    Replies: 0
    Last Post: 03-01-2004, 02:54 AM
  5. Deriving a recordset from a mappoint recordset
    By RichardHayes in forum MapPoint Desktop Discussion
    Replies: 0
    Last Post: 09-06-2002, 03:44 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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127