BUG: Repetitively Saving Maps as HTML Pages by Automation Causes Loss of Pushpins (317977)



The information in this article applies to:

  • Microsoft MapPoint 2002

This article was previously published under Q317977

SYMPTOMS

When you save multiple maps as Web pages (.htm files) by either automating the call to the SaveAs method, or by using the SavedWebPages.Add method, any pushpins are lost after the program saves a large number of pages. The number of times that the program saves .htm files before you receive an error message varies according to the method of saving, and whether your program automates MapPoint directly, or from in the MapPoint Control.

This occurs when you save maps from either MapPoint or from the MapPoint Control. Based on the complexity of the program, you may receive the following error message:
Method Add of Object SavedWebPages failed.

RESOLUTION

To work around this behavior, use one of the following methods depending on your method of saving:

Method 1

If your program uses the SavedWebPages.Add method in the MapPoint Control, the error will occurs after you save 502 maps. To work around this problem, remove the current map from the control after you save 502 maps. This causes MapPoint to quit. Call the Sleep application programming interface (API), with a sleep value of 5000 to 10000 milliseconds to make sure that MapPoint is no longer in the Windows processes list, and then reload a map in the control and continue for 502 more pages.

Method 2

When you use SavedWebPages.Add when you automate MapPoint outside the control, the number of times that the program saves .htm files before the error occurs varies. When the automation program uses this combination, you must experiment to determine the number of pages that are saved before the error occurs. As soon as the automation program reaches this number, save the current map, and then quit MapPoint.

After MapPoint quits, the automation program can create a new instance of MapPoint, load the next map to process, and continue to add to the SavedWebPage collection. The program can repeat this process each time that the count of saved Web pages reaches the number that you determined through experimentation.

Method 3

When the automation program uses call to the SaveAs method, the pushpins disappear from the saved .htm file and from the active map in MapPoint after the program saves 137 times. After the pushpins disappear, MapPoint may become unstable and may stop responding.

To work around this behavior, quit MapPoint when the SaveAs method successfully saves 131 maps, and then create a new instance of MapPoint and continue to save maps as web pages.

Before you remove the current map from the control or quit MapPoint, the automation program needs to save any applicable values that it needs to reload to run with the new instance of MapPoint. Often, you can save these values by assigning them to global variables.

STATUS

Microsoft has confirmed that this is a problem in Microsoft MapPoint 2002.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. In Visual Basic 6.0, create a Standard EXE project. By default, Form1 is created.
  2. On the Project menu, click Components, click Microsoft MapPoint Control 9.0, and then click OK.
  3. Place a MapPoint Control, a command button control, and a Timer control on a large form. Size the MapPoint Control so that it fills as much of the form as possible.
  4. Add the following code to the code module of the form:
    Option Explicit
    
    Public oApp As MapPointCtl.Application
    Public oMap As MapPointCtl.Map
    Public oResults As MapPointCtl.FindResults
    Public oWebPage As MapPointCtl.SavedWebPage
    Public oWebPages As MapPointCtl.SavedWebPages
    Public oLocation As MapPointCtl.Location
    Public lCount As Long
    Public objTextbox As MapPointCtl.Shape
    
    Private Sub Command1_Click()
        lCount = 0
        MappointControl1.NewMap (geoMapNorthAmerica)
        Set oMap = MappointControl1.ActiveMap
        
        Set oResults = oMap.FindAddressResults("16011 N.E. 36th Way", "Redmond", "", "WA", "98052", 244)
        If oResults.Count >= 1 Then
            Set oLocation = oResults.Item(1)
            oLocation.GoTo
            oMap.Altitude = 3
            oMap.AddPushpin AtLocation:=oResults.Item(1)
        End If
        
        Dim objLoc As MapPointCtl.Location
        Set objLoc = oMap.XYToLocation(320, 260)
        Set objTextbox = oMap.Shapes.AddTextbox(objLoc, 60, 30)
        objTextbox.Text = lCount      ' Displays the iteration number
        objTextbox.FontColor = vbRed  ' For emphasis
        Timer1.Interval = 1000
        Timer1.Enabled = True
    End Sub
    
    Private Sub SaveMap()
        Timer1.Enabled = False
        If lCount = 502 Then MsgBox "The next copy of the WebPage will lose its pushpin", vbMsgBoxSetForeground
            
        Set oWebPage = oMap.SavedWebPages.Add(FileName:=App.Path & "\Image.htm", Location:=oLocation, Title:="New Web")
        lCount = lCount + 1
        objTextbox.Text = lCount
        oWebPage.Save
        If lCount = 503 Then MsgBox "Double-click the GIF and see if it lost the pushpin", vbMsgBoxSetForeground
        
        Timer1.Enabled = True
    End Sub
    
    Private Sub Timer1_Timer()
        SaveMap  ' Call the working procedure
    End Sub
    					
  5. Save the project to a folder. This folder becomes the application folder.
  6. Press F5 to run the project. The form opens without a map in the area that the MapPoint Control uses.
  7. Click the command button. The click event of the command button loads the map of North America, sets a pushpin in the middle of the Microsoft campus, and then draws a shape that contains a textbox in the center of the map. The text box displays the iteration count.
  8. The Timer control causes the map to be saved as a Web page (.htm file) every time the Timer control fires. The Timer control saves both the .htm file and its associated graphic (.gif) file in the application folder.
  9. While the demonstration cycles (about one time per second), locate the .gif file, and then double-click the file to display it. You see the text box control which displays the cycle count at the time that the .gif file was saved. To the right of the text box you see a single pushpin.
  10. Let the demonstration cycle 502 times, after which a dialog box appears and alerts you to the impending loss of data.
  11. When you see the first message box, examine the .gif to see the pushpin.
  12. Dismiss the message box.
  13. In about 30 seconds a second message box alerts you to the loss of data. Dismiss the message box, and then examine the .gif file.


Because each Web page is saved with the same name in the same directory, the count of SavedWebPages never exceeds 2 and settles at 1 after the second iteration. CPU memory utilization climbs for about the first 20 iterations, then stabilizes, vacillating 5 megabytes on either side of the midpoint of memory utilization.

REFERENCES

For additional information, click the article numbers below to view the articles in the Microsoft Knowledge Base:

302885 HOWTO: Use the MapPoint 2002 Control and Automation With Visual Basic to Save a Map as HTML

302897 HOW TO: Automate the MapPoint 2002 Control and Save the Map as HTML in Visual Basic .NET


Modification Type:MajorLast Reviewed:5/9/2002
Keywords:kbAutomation kbbug kbDSupport KB317977