Feb 19th, 2003, 04:48 PM
VB - Validating Clipboard Data before Pasting
Frequently, a textbox will be intended to accept specific types of data, ie: currency values, other numeric input or any custom formatted data. When using the standard textbox, this situation brings up the problem of the user pasting the wrong type of data into the textbox. While it is always possible to validate this input in the Change event or at some other convenient and logical point in your code, it may be desirable to prevent the improper data from being pasted in the first place.
The attached example subclasses the textbox to intercept the windows Paste message. The code can then validate the text stored on the clipboard and take appropriate action if it does not fit the criteria for the textbox.
This example was written to allow multiple textboxes to be subclassed simultaneously.
Please note: When running this project in the VB IDE, it is important to close the project by the 'Exit' button or the form's control box. Stopping execution of the program by using the 'Stop' command from the IDE toolbar or menu will cause the project and VB to crash immediately, loosing any unsaved changes.
(There are steps you can take to protect yourself, however these are beyond the scope of this example.)
Click Here to Expand Forum to Full Width
Survey posted by VBForums.