Microsoft KB Archive/89232

= Limiting User Input in a VB for MS-DOS Text Box =

PSS ID Number: 89232

Article Last Modified on 1/9/2003

-

The information in this article applies to:


 * Microsoft Visual Basic for MS-DOS 1.0

-



This article was previously published under Q89232



SUMMARY
In Microsoft Visual Basic for Windows, you can limit the amount of text that can be entered into a text box by calling an internal Windows function and specifying the maximum text limit. However, in Microsoft Visual Basic for MS-DOS, there is no callable function to limit the amount of text entered into a text box. To work around this difference, the text limit can be set by checking the length of the text string in the KeyPress event of that text box and setting the input value, KeyAscii, to zero or null. This method is also compatible with Microsoft Visual Basic version 1.0 for Windows.



MORE INFORMATION
To limit text in a text box in Microsoft Visual Basic for MS-DOS, you must check the length of the text in the text box while in the KeyPress event procedure. If the length of the text is equal to the limit you specify, then set KeyAscii to zero. This will effectively prevent users from entering any more text. Enhancements can be added to handle backspaces and other characters.

The following example demonstrates how to limit text in a text box in Microsoft Visual Basic version 1.0 for MS-DOS:

 Create a new form called Form1. Add a text box (Text1) to Form1.  Add the following code to the KeyPress event of the text box: CONST TEXTLIMIT = 5 CONST KEY_BACK = 8 IF (LEN(text1.text) >= TEXTLIMIT) AND (keyascii <> KEY_BACK) THEN keyascii = 0  From the Run menu, choose Start to run the program.

Notice that the amount of text the text box will allow you to enter is set by the TEXTLIMIT constant. This example allows the user to use the BACKSPACE key.

Additional query words: VBmsdos 1.00

Keywords: KB89232

Technology: kbAudDeveloper kbVB100DOS kbVBSearch kbZNotKeyword3

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© 2004 Microsoft Corporation. All rights reserved.