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

Weird problem with MapPoint shapes and Combo Boxes

This is a discussion on Weird problem with MapPoint shapes and Combo Boxes within the MapPoint Desktop Discussion forums, part of the Map Forums category; Something really weird is happening when I try to add the name of a shape to a combo box using ...

  1. #1
    Anonymous is offline Senior Member Black Belt
    Join Date
    Jul 2002
    Posts
    5,137

    Weird problem with MapPoint shapes and Combo Boxes

    Something really weird is happening when I try to add the name of a shape to a combo box using VB 6.0. Below is an example that reproduces the error. I created a single form with one command button and one combo box (cmbTest) then attached the following code to the command button. g_oApp was previously attached to the MapPoint object.

    Code:
    Private Sub Command2_Click()
        Dim oMap As MapPoint.Map
        Dim oShape As MapPoint.Shape
        
        Set oMap = g_oApp.ActiveMap
        
        oMap.FindResults("Pacific Ocean")(1).GoTo
    
        Dim locLA, locTokyo As MapPoint.Location
        Set locLA = oMap.FindResults("Los Angeles, California")(1)
        Set locTokyo = oMap.FindResults("Tokyo, Japan")(1)
    
        ' Create and name the shape
        Set oShape = oMap.Shapes.AddLine(locLA, locTokyo)
        oShape.Name = "Tokyo Route"
        
        Me.cmbTest.AddItem oShape.Name
    
    End Sub
    You would think that "Tokyo Route" would appear in the combo box.. but instead I get "T". I can't figure it out. If I do a "MsgBox oShape.Name" I get the full name but the combo box only shows the first letter. I have found a work around but it is very annoying and doesn't make any sense.


    Code:
    Private Sub Command2_Click()
        Dim oMap As MapPoint.Map
        Dim oShape As MapPoint.Shape
        Dim iNameA, iNameB As String
    
        Set oMap = g_oApp.ActiveMap
        
        oMap.FindResults("Pacific Ocean")(1).GoTo
    
        Dim locLA, locTokyo As MapPoint.Location
        Set locLA = oMap.FindResults("Los Angeles, California")(1)
        Set locTokyo = oMap.FindResults("Tokyo, Japan")(1)
    
        ' Create and name the shape
        Set oShape = oMap.Shapes.AddLine(locLA, locTokyo)
        oShape.Name = "Tokyo Route"
        
        iNameA = mpShape.Name
        iNameB = iNameA  
        Me.cmbTest.AddItem iNameB
    
    End Sub
    Can anyone else confirm this. Is it just my computer. I suspect there is some weird compilation error. Or am I just missing something.

  2. #2
    John Meyer's Avatar
    John Meyer is offline Senior Member Blue Belt
    Join Date
    Jul 2002
    Posts
    478
    I ran your code (the first sample) and I got "Tokyo Route" in the combo box. I don't know what to tell you? Sorry...

  3. #3
    Anonymous is offline Senior Member Black Belt
    Join Date
    Jul 2002
    Posts
    5,137
    Quote Originally Posted by John Meyer
    I ran your code (the first sample) and I got "Tokyo Route" in the combo box. I don't know what to tell you? Sorry...
    What version of VB are you using?

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

  5. #5
    Bob Chase is offline Junior Member Yellow Belt
    Join Date
    Mar 2003
    Posts
    13

    Weird behavior

    This may help explain some weird behavior:

    Dim iNameA, iNameB As String

    does not declare two variables of type String. Instead, iNameA has actually declared as a variant. Unlike other languages, VB 6 does not interpret a declaration like the following

    Dim i, j, k as Integer

    to be a declaration of 3 integers. Instead, "i" and "j", since they are not explicitly assigned a type, are automatically typed as variants. In effect, the code above is equivalent to

    Dim i
    Dim j
    Dim k as integer.

    You can check out what I am saying with the following code:

    Public Sub Test()

    Dim i as Variant
    Dim j, k as integer

    Debug.Print TypeName(i)
    Debug.Print TypeName(j)
    Debug.Print TypeName(k)

    End Sub

  6. #6
    Anonymous is offline Senior Member Black Belt
    Join Date
    Jul 2002
    Posts
    5,137

    Re: Weird behavior

    Quote Originally Posted by Bob Chase
    This may help explain some weird behavior:

    Dim iNameA, iNameB As String

    does not declare two variables of type String. Instead, iNameA has actually declared as a variant. Unlike other languages, VB 6 does not interpret a declaration like the following

    Dim i, j, k as Integer

    to be a declaration of 3 integers. Instead, "i" and "j", since they are not explicitly assigned a type, are automatically typed as variants. In effect, the code above is equivalent to

    Dim i
    Dim j
    Dim k as integer.

    You can check out what I am saying with the following code:

    Public Sub Test()

    Dim i as Variant
    Dim j, k as integer

    Debug.Print TypeName(i)
    Debug.Print TypeName(j)
    Debug.Print TypeName(k)

    End Sub
    That does help somewhat. It looks to me that for some odd reason my version of VB (or it could be MapPoint) is returning strange names for the shapes. Coping the shapes name into a variant seams to correct the problem. So the following code works but I still don't know what is wrong with my shape names.

    Code:
    Private Sub Command2_Click()
        Dim oMap As MapPoint.Map
        Dim oShape As MapPoint.Shape
        Dim iNameA As Variant
        
        Set oMap = g_oApp.ActiveMap
        
        oMap.FindResults("Pacific Ocean")(1).GoTo
    
        Dim locLA, locTokyo As MapPoint.Location
        Set locLA = oMap.FindResults("Los Angeles, California")(1)
        Set locTokyo = oMap.FindResults("Tokyo, Japan")(1)
    
        ' Create and name the shape
        Set oShape = oMap.Shapes.AddLine(locLA, locTokyo)
        oShape.Name = "Tokyo Route"
        
        iNameA = oShape.Name
        Me.cmbTest.AddItem iNameA
    
    End Sub
    BTW... John are you using SP5?

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

    Try using the ActiveX control and see if it makes a difference.

    Code:
    Dim oMap As MapPointctl.Map
    Set oMap = MappointControl1.ActiveMap
    Dim oShape As MapPointctl.Shape
        
    oMap.FindResults("Pacific Ocean")(1).GoTo
    
    Dim locLA, locTokyo As MapPointctl.Location
    Set locLA = oMap.FindResults("Los Angeles, California")(1)
    Set locTokyo = oMap.FindResults("Tokyo, Japan")(1)
    
    ' Create and name the shape
    Set oShape = oMap.Shapes.AddLine(locLA, locTokyo)
    oShape.Name = "Tokyo Route"
        
    Me.cmbTest.AddItem oShape.Name

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Mapping PO Boxes
    By MeliDe in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 10-21-2005, 01:42 PM
  2. Fill the shapes with colors problem
    By vidyakulkarni in forum MapPoint Desktop Discussion
    Replies: 4
    Last Post: 09-28-2004, 09:05 AM
  3. Copying Worksheet with Combo Box
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 0
    Last Post: 07-20-2004, 04:13 PM
  4. Hiding Boxes around Label shapes
    By andrem in forum MapPoint Desktop Discussion
    Replies: 3
    Last Post: 09-25-2003, 12:09 PM
  5. Text Boxes
    By ClactonEssex in forum Wish List
    Replies: 0
    Last Post: 12-10-2002, 07:52 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