Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual Basic
Expertise: Beginner
Oct 1, 1996

Programmatically Clearing a Text Box

Question:
I have a series of text boxes, any subset of which can be used for input of numerical data, followed by a command box to "compute" from that input and write results back to the boxes. If a second, new set of data is to be entered, I would like to automatically clear the boxes when I click a "new" control button. Using the syntax Text1="" results in a string being read the next time "compute" is clicked and a data type error when a data check is made for non-zero data having been entered. Using the syntax Text1=0 puts a zero in the box, but when I begin typing the new number in, it is as if the keyboard mode is in Ins, rather than Typeover (neither keyboard mode affects the result), and an integer entered is read in with the extra trailing zero making it 10X too large. How can I clear the text boxes back to their uninitialized state that they had when the program was launched, such that they are blank and read as numerical zeros unless non-zero data is entered?

Answer:
Try the .Clear method on the text box. It is designed not to generate events. Alternatively, if the Clear does generate a Change event, simply set a flag before you clear the box. In the Change event for the text box, if the flag is set, ignore the change that was made. I've used this method several times successfully.

DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date