Microsoft KB Archive/317977

= BUG: Repetitively Saving Maps as HTML Pages by Automation Causes Loss of Pushpins =

Article ID: 317977

Article Last Modified on 5/9/2002

-

APPLIES TO


 * Microsoft MapPoint 2002 Standard Edition

-



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.



Steps to Reproduce the Behavior
 In Visual Basic 6.0, create a Standard EXE project. By default, Form1 is created. On the Project menu, click Components, click Microsoft MapPoint Control 9.0, and then click OK. 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.  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(&quot;16011 N.E. 36th Way&quot;, &quot;Redmond&quot;, &quot;&quot;, &quot;WA&quot;, &quot;98052&quot;, 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 &quot;The next copy of the WebPage will lose its pushpin&quot;, vbMsgBoxSetForeground Set oWebPage = oMap.SavedWebPages.Add(FileName:=App.Path & &quot;\Image.htm&quot;, Location:=oLocation, Title:=&quot;New Web&quot;) lCount = lCount + 1 objTextbox.Text = lCount oWebPage.Save If lCount = 503 Then MsgBox &quot;Double-click the GIF and see if it lost the pushpin&quot;, vbMsgBoxSetForeground Timer1.Enabled = True End Sub

Private Sub Timer1_Timer SaveMap ' Call the working procedure End Sub  Save the project to a folder. This folder becomes the application folder. Press F5 to run the project. The form opens without a map in the area that the MapPoint Control uses.</li> 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.</li> 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.</li> 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.</li> Let the demonstration cycle 502 times, after which a dialog box appears and alerts you to the impending loss of data.</li> When you see the first message box, examine the .gif to see the pushpin.</li> Dismiss the message box.</li> 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.</li></ol>

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.

<div class="references_section">