PRB: Visual Basic Control with Font Properties Crashes Program

Last reviewed: February 20, 1998
Article ID: Q181414
The information in this article applies to:
  • Microsoft Visual Basic Control Creation, Learning, Professional, and Enterprise Editions for Windows, version 5.0

SYMPTOMS

An ActiveX control created in Visual Basic contains font properties. When this control is used in a Web authoring environment, such as FrontPage or the ActiveX Control Pad, the Web authoring environment crashes or produces the following error:

   Run-time error '50003':
   Unexpected Error

CAUSE

Visual Basic is attempting to write the font properties to an Object type in the property bag.

RESOLUTION

To persist font information for an ActiveX control that will be used in an HTML document, write out each font property separately to the property bag. This solution is illustrated in the MORE INFORMATION section of this article.

STATUS

Microsoft is researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

The following code for a sample control illustrates this problem. Notice that a font object is written to the property bag:

   Private m_Font As New StdFont 'defines as Font object

   Private Sub UserControl_InitProperties()
      m_Font.Bold = False
      m_Font.Italic = False
      m_Font.Name = "Arial"
      m_Font.Size = 10
      m_Font.Strikethrough = False
      m_Font.Underline = False
   End Sub

   Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
      On Error Resume Next
      Set m_Font = PropBag.ReadProperty("Font")
   End Sub

   Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
      PropBag.WriteProperty "Font", m_Font
   End Sub

To correct this problem, write each font property separately to the property bag, as in this example:

   Private m_Font As New StdFont 'defines as Font object

   Private Sub UserControl_InitProperties()
      m_Font.Bold = False
      m_Font.Italic = False
      m_Font.Name = "Arial"
      m_Font.Size = 10
      m_Font.Strikethrough = False
      m_Font.Underline = False
   End Sub

   Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
      On Error Resume Next
      m_Font.Bold = PropBag.ReadProperty("FontBold")
      m_Font.Italic = PropBag.ReadProperty("FontItalic")
      m_Font.Name = PropBag.ReadProperty("FontName")
      m_Font.Size = PropBag.ReadProperty("FontSize")
      m_Font.Strikethrough = PropBag.ReadProperty("FontStrikethrough")
      m_Font.Underline = PropBag.ReadProperty("FontUnderline")
   End Sub

   Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
      PropBag.WriteProperty "FontBold", m_Font.Bold
      PropBag.WriteProperty "FontItalic", m_Font.Italic
      PropBag.WriteProperty "FontName", m_Font.Name
      PropBag.WriteProperty "FontSize", m_Font.Size
      PropBag.WriteProperty "FontStrikethrough", m_Font.Strikethrough
      PropBag.WriteProperty "FontUnderline", m_Font.Underline
   End Sub


Additional query words: front page internet ocx usercontrol
Keywords : vb5all kberrmsg
Technology : kbole
Version : WINDOWS:5.0
Platform : WINDOWS
Issue type : kbprb
Solution Type : kbpending


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 20, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.