List Boxes Can Shrink When a Form Is Saved in Text Format

Last reviewed: January 5, 1996
Article ID: Q141940
The information in this article applies to:

- Standard and Professional Editions of Microsoft Visual Basic,

  16-bit only, for Windows, version 3.0

SYMPTOMS

Every time a project is run, a list box appears with a smaller height than when the form was previously saved. The behavior seems to depend on whether the form was saved in text format or binary, and the font used in the list box. The list box does not grow any smaller once an executable is made.

The same problem described above can also occur for a file list box.

STATUS

This problem was fixed in both 16- and 32-bit versions of Visual Basic 4.0 (where all forms are saved only in a text format).

MORE INFORMATION

The problem described above occurs under certain circumstances. First, the height of the list box shrinks after the form has been saved in text format. (To save a form in text format, highlight the form in the project window and on the File menu, click Save File As, with the Save As Text check box selected.) If the form is saved consistently in the Binary format, then the problem is not reproducible.

Secondly, the problem seems to only occur for certain fonts in the list box. MS Sans Serif and Truetype fonts such as Arial are font choices where the problem does not occur. Small Fonts and Courier are examples of fonts in the list box where the problem does occur.

Workaround

The following are three possible workarounds:

  • Explicitly set the height of the list box in the Load event of the form. This will always override whatever height is specified in the property window at design time.

    For example, in the Form_Load event, place the following line of code:

          List1.Height = 3860  'Scalemode of the form is set for Twips
    

    -or-

  • Consistently save the form in binary format. The problem only appears when the program is run after saving the form in text format.

    -or-

  • Choose a font for the list box where the problem is not reproducible, such as MS Sans Serif.

Steps to Reproduce the Problem

  1. Start a new Visual Basic project. Form1 appears by default.

  2. Place a list box on the form (it will be called List1 by default) and set the height property of the list box to 6630 twips (or a suitable high value).

  3. In the property window, set the FontName for the list box to Small Fonts. Also, type in a size of 24 for the font (the problem occurs for all sizes of the font, but is most easily seen for larger sizes).

  4. In the Activate event for the form, place the following line of code:

          Debug.Print List1.Height
    

  5. Run the program by pressing the F5 key. Notice that the Debug window correctly shows the original height of the list box. Stop the program.

  6. Save Form1 in a text format, that is, on the File menu, click Save File As, and check the Save As Text check box.

  7. Run the program by pressing the F5 key. Notice that the debug window still shows the original height of the list box. Stop the program.

  8. Save Form1 once again in text format--when Visual Basic asks if you want to replace Form1, click Yes.

  9. Run the program again. Now the Debug window shows that the list box height has decreased to 6030 twips.

After each successive save of the form in text format, the list box height will decrease every time the project is run. However, the problem only surfaces after the second save of the form in text format.


Additional reference words: 3.00 4.00
KBCategory: kbfixlist kbusage
KBSubcategory: prgctrlsstd


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