By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,442 Members | 1,358 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,442 IT Pros & Developers. It's quick & easy.

Is backspace considered character?

P: n/a
In my program the text-box should accept only integers and it should prompt a message if a character is entered in the text box. But it is taking the backspace button that the user may use to clear the entered data as a character and prompting warning message
How can i make the backspace not be considered a character or make the program accept integers and backspace?

this is the try catch statement I'm using to handle the character entering error:

Expand|Select|Wrap|Line Numbers
  1.  Dim z As Integer
  3.         Try
  4.             z = CInt(TxtQP.Text)
  5.         Catch ex As Exception
  6.             MessageBox.Show("Characters are not allowed, Please Enter a Number")
  7.             TxtQP.Text = 1
  8.             TxtQP.Focus()
  9.             Exit Sub
  10.         End Try
Oct 18 '10 #1
Share this Question
Share on Google+
1 Reply

Expert 100+
P: 983
You need to test for the backspace character, and if it's there, fix up the input.

Maybe something like this:

Expand|Select|Wrap|Line Numbers
  1. If Right$(TxtQP.Text, 1) = vbBs Then
  2.   TxtQP = Left$(TxtQP, len(TxtQP)-1)
  3. End If

Or is the backspace not showing up in the string, but as the input character kicking off your procedure?
Oct 18 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.