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

ID: Q89232


The information in this article applies to:
  • Microsoft Visual Basic Standard and Professional Editions for MS-DOS, version 1.0


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:

  1. Create a new form called Form1.


  2. Add a text box (Text1) to Form1.


  3. 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 


  4. 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 :
Version : MS-DOS:1.0
Platform : MS-DOS
Issue type :


Last Reviewed: December 9, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.