BUG: Invalid Index Passed to Screen.Fonts Collection Causes GPF

Last reviewed: February 5, 1998
Article ID: Q180526
The information in this article applies to:
  • Windows CE Toolkit for Visual Basic 5.0, version 1.0

SYMPTOMS

An application error may occur within the Windows CE emulator (pvb.exe) if an invalid index is passed to the Screen.Fonts collection. The error is as follows:

    The instruction at "0x01000a68b" referenced memory at "0x00000034".
    The memory could not be "read".

On the actual Windows CE device, this error causes the application to end without an error dialog.

RESOLUTION

Ensure that the index that is passed to the Screen.Fonts collection is valid. The following code sample shows how a function (IsValidFontIndex) can be used to ensure that the error does not occur:

   Option Explicit
   Private Sub Command1_Click()
      Dim iFontNumber
      'Set iFontNumber to an invalid Screen.Font index value.
      iFontNumber = Screen.FontCount
      If IsValidFontIndex(iFontNumber) Then
         Command1.Font = Screen.Fonts(iFontNumber)
      Else
         'Insert some other error handling or set
         'the font to a default font.
         MsgBox "Invalid Font Index"
      End If
   End Sub

   Private Function IsValidFontIndex(Index)
      If Index >= Screen.FontCount Then
         IsValidFontIndex = False
      Else
         IsValidFontIndex = True
      End If
   End Function

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

Steps to Reproduce Behavior

WARNING: The following code sample will produce an application error in PVB.EXE.

  1. Start a new Windows CE Project in Visual Basic 5.0. Form1 is created by default.

  2. Add a CommandButton to Form1.

  3. Paste the following code into the Declarations section of Form1:

          Private Sub Command1_Click()
    
             Dim iFontNumber
             'Set iFontNumber to an invalid Screen.Font index value.
             iFontNumber = Screen.FontCount
             'The following line of code will produce
             'an application error in PVB.EXE.
             Command1.Font = Screen.Fonts(iFontNumber)
          End Sub
    
    

  4. Press the F5 key to run the project and note that pressing the Command1 button will produce an application error.

(c) Microsoft Corporation 1998, All Rights Reserved. Contributions by Mike Dixon, Microsoft Corporation
Keywords          : vb5all vbce
Version           : WINDOWS:1.0
Platform          : WINDOWS
Issue type        : kbbug
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 5, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.