Cannot clear a text box in VB

sasllc
sasllc used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
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.
Commented:
inside the keypress event use
e.KeyChar = "" which will subsitute the pressed key with a zero length string

Author

Commented:
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!

Commented:
make sure you don't call the other form by doing form1.textbox1.text = "" from inside an other form, you can only access this form by calling it through my.application.openforms("form1").textbox1.text = "".
Give that a try ;-)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial