Is backspace considered character?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Aamna

    Is backspace considered character?

    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:

    Code:
     Dim z As Integer
    
            Try
                z = CInt(TxtQP.Text)
            Catch ex As Exception
                MessageBox.Show("Characters are not allowed, Please Enter a Number")
                TxtQP.Text = 1
                TxtQP.Focus()
                Exit Sub
            End Try
    THANK YOU!
    Last edited by MMcCarthy; Oct 18 '10, 07:50 PM. Reason: added code tags
  • Oralloy
    Recognized Expert Contributor
    • Jun 2010
    • 988

    #2
    You need to test for the backspace character, and if it's there, fix up the input.

    Maybe something like this:

    Code:
    If Right$(TxtQP.Text, 1) = vbBs Then
      TxtQP = Left$(TxtQP, len(TxtQP)-1)
    End If
    Luck!

    Or is the backspace not showing up in the string, but as the input character kicking off your procedure?

    Comment

    Working...