inside the keypress event use
e.KeyChar = "" which will subsitute the pressed key with a zero length string
I am having trouble clearing a text box in a VS 2005 VB project. I'm trying to do it the same way I've done it so many times before on other text boxes in various projects, but I just can't get it to clear, and cannot see what I'm missing.
The text box is named txtBale. Sometimes I key an "M" into this text box, and in my code I have a KeyPressEvent that sees that I keyed in that character, then calls another form which does a few things, then comes back to the calling form, and at that point I'm trying to clear the M from the text box--but never can get it to clear. I'm trying usual things such as:
me.txtBale.text = ""
me.txtBale.focus()
me.txtBale.refresh()
...in various combinations, as well as a few other statements that I was not really familiar with---that didn't help anyway. The M just hangs in that text box on the screen---unless I manually press the backspace key on my keyboard. I think that the program IS putting the "" in the text box, but I think it is placing it to the right of the M that is showing on the screen. The reason I say this is because I tried saying:
me.txtBale.text = "77" (instead of = "")
and after it ran that statement, it showed "M77" in the text box.
Any idea what I'm missing here, or how to completely clear all data from the text box and from the screen? TIA
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I never could get e.KeyChar = "" to work, because I got a syntax error saying that Property 'KeyChar' is 'ReadOnly'....so I don't understand that.
But I did finally see one difference in my code that I never noticed before; other sections of the program that ARE working right include this line of code:
e.Handled = True
And when I added that to this new code that handles the "M", then it all started working right. I don't understand WHY that fixes it, nor have I ever understood the meaning or the point of that one statement. So, if anyone can enlighten me--in simple terms--I would appreciate it!
In any case, thanks for the help!
Business Accounts
Answer for Membership
by: TechSingerPosted on 2009-07-21 at 08:20:37ID: 24905532
What you're trying should do exactly what you want it to. The fact that the "M" keeps showing up says there is something unexpected going on.
Look through your code and make sure you don't have a procedure that Handles the ChangValue event of the text box. Also, make sure you don't have any other controls in the same area that may be under the one you are trying to use.
Also, go through a debug and check the value of the text. That should help you troubleshoot it.