Microsoft KB Archive/180526

{|
 * width="100%"|

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

 * }

Q180526

-

The information in this article applies to:


 * Microsoft 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 problem in the Microsoft products that are listed at the beginning of this article.

This problem was corrected in Windows CE Toolkit for Visual Basic 6.0.

Steps to Reproduce Behavior
WARNING: The following code sample will produce an application error in PVB.EXE.

 Start a new Windows CE Project in Visual Basic 5.0. Form1 is created by default. Add a CommandButton to Form1.  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  Press the F5 key to run the project and note that pressing the Command1 button will produce an application error.

© Microsoft Corporation 1999, All Rights Reserved.

Contributions by Mike Dixon, Microsoft Corporation

Additional query words: wince vbce vbce5 vbce6

Keywords : kbToolkit kbVBp kbVBp500bug kbVBp600fix kbOSWinCEsearch kbOSWinCE100 kbGrpDSVB

Issue type : kbbug

Technology : kbVBSearch kbAudDeveloper kbWinCETKVBSearch kbWinCESearch kbWinCETK100VB500