PRB: "Invalid Property Value" If TrueType Fonts Only Selected

Last reviewed: October 30, 1995
Article ID: Q129934
The information in this article applies to:
  • Standard, Professional, and Enterprise Editions of Microsoft Visual Basic, 16-bit and 32-bit, for Windows, version 4.0
  • Standard and Professional Editions of Microsoft Visual Basic for Windows, version 3.0

SYMPTOMS

If you have "TrueType fonts only" set in the Fonts applet in the Windows Control Panel, when you execute Visual Basic code that sets a Fontname property of a form or control to "MS Sans Serif" (or any other non-TrueType font), the program generates error 380:

   Invalid property value

This error can also be generated when you execute the following statement if the FontName property of the Form is a Non-TrueType font (which it is by default):

   Form1.FontName = Form1.FontName

This is true even though the default FontName value is MS Sans Serif. This is because the FontName property is set by default to a non-TrueType font. If you change the FontName property to Arial at design time, you will not get the "Invalid property Value" error, because Arial is a TrueType Font

CAUSE

MS Sans Serif is the default font for every control created in Visual Basic. Visual Basic does not detect the 'True Types only' setting in the Fonts applet and is, therefore, unaware of the fact that "MS Sans Serif" is an invalid font choice. When the program causes an assignment of the Fontname, Visual Basic is bound to the 'True Types only' setting and rejects any Fontnames not on the list.

RESOLUTION

If you need to set your Fontname property, you can guarantee that the font chosen is valid by stepping through the Screen.Fonts collection with this code:

   Private Sub Form_Load()
      Dim AFontName As String
      Dim ItsLegal As Integer

      AFontName = "MS Sans Serif"

      For I = 1 To Screen.FontCount - 1
         If AFontName = Screen.Fonts(I) Then
            ItsLegal = True
            Exit For
         End If
      Next
      If ItsLegal Then
         Form1.FontName = AFontName
      Else
         MsgBox AFontName & " is not available."
      End If
   End Sub

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Start the Windows Control Panel in the Main group in Program Manager.

  2. Start the Fonts applet.

  3. Click the TrueType button, and select the "Show Only True Type Fonts in Applications" check box. Click OK.

  4. Start a new project in Visual Basic. Form1 is created by default.

  5. Add the following code to the Form1_Load procedure:

       Sub Form1_Load()
          Form1.Fontname = Form1.Fontname
       End Sub
    
       -or-
    
       Sub Form1_Load ()
          Form1.Fontname = "MS Sans Serif"
       End Sub
    
    

  6. Start the program by pressing the F5 key.

With either code segment, the application generates error 380.


Additional reference words: 4.00 vb4win vb4all
KBCategory: kbprg kbprb kberrmsg kbcode
KBSubcategory: PrgOther


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: October 30, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.