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

Alpha-numeric labels for polys

This is a discussion on Alpha-numeric labels for polys within the Development forums, part of the MapPoint Desktop Discussion category; Hi. I am trying to relabel all polys with consecutive letters + number of records. The code I have is ...

  1. #1
    karissao is offline Junior Member White Belt
    Join Date
    Jan 2011
    Posts
    1

    Alpha-numeric labels for polys

    Hi. I am trying to relabel all polys with consecutive letters + number of records. The code I have is in excel macro. It is giving the number of records correctly, but instead of A, B, C, the letters to the groups are off by quite a bit. I think its something minor. Anyone care to clean this up a bit? Thanks in advance!!


    Code:
    Public Sub LabelAllPolysABC()
    
        Dim timeStart As Date
        timeStart = Now()
    
        Set MPApp = GetObject(, "MapPoint.Application")
        MPApp.Activate
            
        Dim objMap As MapPoint.Map
        Set objMap = MPApp.ActiveMap
            
        Dim polysetnum As Integer
        Dim polysetname As String
        Dim objPoly, objTextBox As MapPoint.Shape
        Dim objDataset As MapPoint.DataSet
        Dim objRecords As MapPoint.Recordset
        Dim objLocation As MapPoint.Location
        Dim dblLat, dblLon As Double
        Dim mapnum, flag, Abort_Setting As Long
        Dim row, col, abort, locs As Long
        Dim objField As MapPoint.Field
    
        Set objDataset = objMap.DataSets(1)
    
        'remove any existing labels
        For Each objTextBox In objMap.Shapes
          If objTextBox.Type = 17 Then 'is textbox
            objTextBox.Delete
          End If
        Next
    
        For Each objPoly In objMap.Shapes
          If objPoly.Type = 5 Then 'is freeform
            Set objRecords = objDataset.QueryShape(objPoly)
            Do While Not objRecords.EOF
              lngCount = lngCount + 1
              'slowest part of program - just read lat/lon of every tenth location
              If lngCount Mod 20 = 1 Then
                dblLat = dblLat + objRecords.Location.Latitude
                dblLon = dblLon + objRecords.Location.Longitude
                locCount = locCount + 1
                polysetnum = polysetnum + 1
              End If
              objRecords.MoveNext
            Loop
            'MsgBox "Number of records in shape: " & lngCount
            Set objLocation = objMap.GetLocation(dblLat / locCount, dblLon / locCount)
            Set objTextBox = objMap.Shapes.AddTextbox(objLocation, 35, 30)
            objTextBox.Text = GetPolySetName(polysetnum) & " " & lngCount
          End If
          
          lngCount = 0
          locCount = 0
          dblLat = 0
          dblLon = 0
        Next
        
        MsgBox ("Finished in " & Int((Now() - timeStart) * 24 * 60 * 60) & " seconds.")
        
    End Sub
    Function GetPolySetName(ByVal polysetnum As Integer) As String
      If polysetnum < 27 Then
        GetPolySetName = Chr$(64 + polysetnum)
      ElseIf polysetnum < 53 Then
        polysetnum = polysetnum - 26
        GetPolySetName = Chr$(64 + polysetnum) & Chr$(64 + polysetnum)
      ElseIf polysetnum < 79 Then
        polysetnum = polysetnum - 52
        GetPolySetName = Chr$(64 + polysetnum) & Chr$(64 + polysetnum) & Chr$(64 + polysetnum)
      ElseIf polysetnum < 105 Then
        polysetnum = polysetnum - 78
        GetPolySetName = Chr$(64 + polysetnum) & Chr$(64 + polysetnum) & Chr$(64 + polysetnum) & Chr$(64 + polysetnum)
      Else
        Debug.Print "PolySetName out of bounds! Fix code above to allow up to five or six chars (e.g. AAAAA or AAAAAA)."
        Stop
      End If
    End Function
    Last edited by Eric Frost; 01-13-2011 at 08:55 AM.

  2. #2
    Winwaed's Avatar
    Winwaed is offline Mapping-Tools.com Black Belt
    Join Date
    Feb 2004
    Location
    Irving,Texas
    Posts
    1,859
    Blog Entries
    60

    Re: Alpha-numeric labels for polys

    So the problem isn't really a MapPoint problem at all, but a VBA string formatting problem.

    It might help if you could give some examples of what strings you are getting for what numbers.

    Also for debugging it might be simpler to develop that bit independently of the rest of the script (and MapPoint).


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

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

    Re: Alpha-numeric labels for polys

    >> It is giving the number of records correctly, but instead of A, B, C, the letters to the groups are off by quite a bit. I think its something minor. <<

    Can you explain more, maybe with illustration/screenshots of what you want? I agree the code change is probably minor, but figuring out what you need will take more time

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

  4. #4
    Mattys Consulting's Avatar
    Mattys Consulting is offline Senior Member Black Belt
    Join Date
    Dec 2002
    Posts
    1,040

    Re: Alpha-numeric labels for polys

    Mod 20 = 1 should be Mod 10 = 0
    Michael R Mattys
    Business Process Developers
    www.mattysconsulting.com

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

    Re: Alpha-numeric labels for polys

    Are you joking or how do you explain that to be the solution?

    That part of the code (I wrote) was just for centering to the approximate middle of the set of points. It was kind of slow the way I originally wrote it, so the mod bit was just to tell it to only look at every 20th point, then do the average of those coordinates. Not rocket science, but it worked fine enough.

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

  6. #6
    Mattys Consulting's Avatar
    Mattys Consulting is offline Senior Member Black Belt
    Join Date
    Dec 2002
    Posts
    1,040

    Re: Alpha-numeric labels for polys

    No, I was kidding ...
    The actual answer is that the line "polysetnum = polysetnum + 1"
    should come after the line "Loop"
    Last edited by Mattys Consulting; 01-16-2011 at 10:08 AM.
    Michael R Mattys
    Business Process Developers
    www.mattysconsulting.com

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Wolfram|Alpha Launches Today!
    By Eric Frost in forum General Chat
    Replies: 1
    Last Post: 06-17-2009, 12:22 PM
  2. Simple State map - show only numeric values - not an option??
    By davejago in forum MapPoint Desktop Discussion
    Replies: 9
    Last Post: 10-29-2008, 06:53 AM
  3. Printing without labels
    By srtarpley in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 10-11-2007, 03:55 PM
  4. Labels
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 0
    Last Post: 03-06-2004, 08:34 PM
  5. How to add labels to all pushpins
    By Veitschi in forum MapPoint Desktop Discussion
    Replies: 7
    Last Post: 02-21-2003, 03:24 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