FIX: Out of Memory Error When Adding 35-50 Pen Controls

Last reviewed: October 30, 1997
Article ID: Q110989
2.00 3.00 WINDOWS kbprg kbbuglist

The information in this article applies to:

- Standard and Professional Editions of Microsoft Visual Basic

  programming system for Windows, versions 2.0 and 3.0

SYMPTOMS

You will receive an "Out of Memory" error message if you attempt to add more than approximately 36 HEdit or approximately 50 BEdit Pen Controls to an individual Form.

WORKAROUND

You can edit in only one control at a time, so use only one of each of the Pen Controls on top of multiple Labels or Picture Box Controls. This will display the result of the edit when you move the focus to another control.

The examples in the More Information section below will demonstrate how to do this for each of the Pen Controls.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This problem has been corrected in Visual Basic version 4.0.

MORE INFORMATION

Here are two examples showing how to work around this bug:

Step-by-Step Example One

The following example demonstrates how to use multiple Picture Boxes and one HEdit Control with the DelayRecog = True. This will allow the user to input signatures into a field which will then remain as written, no recognition is performed.

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

  2. Add the following controls, and set the indicated properties:

       Control          Property     Value
       ----------------------------------------
       Picture Box      Name         PictureB
                        Index        0
                        AutoRedraw   True
    
       Picture Box      Name         PictureB
                        Index        1
                        AutoRedraw   True
    
       HEdit Control    Name         HEdit1
                        DelayRecog   True
                        Text         <blank>
    
       Command Button   Name         Command1
                        Caption      Clear
    
    

  3. Add the following code to the General Declarations section of Form1:

       'Enter each of the following Declare statements on one, single line:
       Declare Function GetDC Lib "USER" (ByVal hWnd As Integer) As Integer
       Declare Function BitBlt Lib "GDI" (ByVal hDestDC As Integer,
          ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer,
          ByVal nHeight As Integer, ByVal hSrsDC As Integer,
          ByVal xSrc As Integer, ByVal ySrc As Integer, ByVal dwRop) As Integer
    
          Const SRCCOPY &H00CC0020&  ' Will be used in the call to BitBlt
          Dim LastPos As Integer     ' Will be used to keep track of the
                                     ' last edited field.
          Dim InkArray(2) As String  ' This array will be used to store the
                                     ' InkDataString for each of the fields.
    
    

  4. Add the following code to the appropriate Control's event procedures:

       Sub Command1_Click ()
          HEdit1.InkDataString = ""     ' Clear the field.
       End Sub
    
       Sub Form_Load ()
          Call PictureB_Click(0)    ' Position the HEdit control over the
       End Sub                      ' first field.
    
       Sub Picture1_Click (index As Integer)
          ' Copy the image in the HEdit control to the Picture Box
          destDC = GetDC(HEdit.hWnd)
          ' Enter the following three lines as one, single line:
          dummy% = BitBlt(PictureB(LastPos).HDC, 0, 0,
             PictureB(LastPos).ScaleWidth-2, PictureB(LastPos).ScaleHeight-2,
             destDC, 1, 1)
          InkArray(LastPos) = HEdit1.InkDataString
          ' Save the Ink data for this field.  It will be reassigned
          ' to the HEdit control the next time that field is selected
          ' and the HEdit control is positioned on top of it.
          LastPos = index        ' Update LastPos to the current field.
          HEdit1.Visible = False ' This prevent a flicker when the
                                 ' control is moved.
          HEdit1.Top = PictureB(index).Top     ' Move the HEdit Control on
          HEdit1.Left = PictureB(index).Left   ' top of the selected Picture
          HEdit1.Width = PictureB(index).Width ' box field.
          HEdit1.Height = PictureB(index).Height
          HEdit1.InkDataString = InkArray(index) ' Reset the Ink in the
                                                 ' Hedit Control to that
                                                 ' stored for this field.
          HEdit1.Visible = True
       End Sub
    
    

Step-by-Step Example Two

The following example demonstrates how to use multiple Labels and one HEdit Control with DelayRecog = False. This works using a BEdit control as well. This allows the user to input hand-written characters into a field where those characters will then be recognized and converted into font characters.

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

  2. Add the following controls, and set the indicated properties:

       Control         Property      Value
       -----------------------------------------------------------
       Label           Name          LabelF
                       Index         0
                       Caption       <blank>
    
       Label           Name          LabelF
                       Index         1
                       Caption       <blank>
    
       HEdit Control   Name          HEdit1
                       DelayRecog    False
                       Text          <blank>
    
    

  3. Add the following code to the General Declarations section of Form1:

    Dim LastPos As Integer

  4. Add the following code to the appropriate event procedures:

       Sub Form_Load ()
          Call LabelF_Click (0)
       End Sub
    
       Sub LabelF_Click (index As Integer)
          LabelF(LastPos).Caption = HEdit.Text    ' Copy the contents of
                                                  ' the HEdit Control to  the
                                                  ' Label Control.
          LastPos = index         ' Update LastPos to the current field.
          HEdit1.Visible = False  ' This prevent a flicker when the
                                  ' control is moved.
          HEdit1.Top = LabelF(index).Top       ' Move the HEdit Control on
          HEdit1.Left = LabelF(index).Left     ' top of the selected Picture
          HEdit1.Width = LabelF(index).Width   ' Box field.
          HEdit1.Height = LabelF(index).Height
          HEdit1.Text = LabelF(index).Caption  ' Reset the Ink in the HEdit
                                               ' Control to that stored for
                                               ' this field.
          HEdit1.Visible = True
       End Sub
    


Additional reference words: buglist2.00 buglist3.00 2.00 3.00 fixlist4.00
KBCategory: kbprg kbbuglist
KBSubcategory: PrgCtrlsCus
Keywords : PrgCtrlsCus kbbuglist kbprg
Version : 2.00 3.00
Platform : WINDOWS
Solution Type : kbfix


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