有Backspce相对应的ASCII码吗?请问高手,如何实现在输入时只能敲数字键和退格键!!

解决方案 »

  1.   

    Private Sub Text1_KeyPress(KeyAscii As Integer)
        If IsNumeric(Chr(KeyAscii)) = False And KeyAscii <> 8 Then
            KeyAscii = 0
        End If
    End Sub
      

  2.   


    Private Sub Form_Load()
    Me.KeyPreview = True
    End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)
    If Not InStr("1234567890" & Chr(8), Chr(KeyAscii)) > 0 Then KeyAscii = 0
    End Sub
      

  3.   

    Private Sub Text1_KeyPress(KeyAscii As Integer)
        Select Case KeyAscii
            Case Asc("-") '不允许负数
                    KeyAscii = 0
              Case 8 '无变化,退格键不屏蔽
              Case Asc(" ") '不允许空格
                    KeyAscii = 0
              Case Asc(".") '46 '不允许小数点
                    KeyAscii = 0
              Case Is < Asc(0) '48
                    If KeyAscii <> vbKeyReturn Then KeyAscii = 0
              Case Is > Asc(9) '57
                    KeyAscii = 0
        End Select    Exit Sub
    End Sub
      

  4.   

    Private Sub text1_KeyPress(KeyAscii As Integer)
        If ((KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 And KeyAscii <> 9) Then
            KeyAscii = 0
        End If
    End Sub
      

  5.   

    Private Sub Text1_KeyPress(KeyAscii As Integer)
    If Not (KeyAscii = 8 Or (KeyAscii >= 48 And KeyAscii <= 57)) Then KeyAscii = 0
    End Sub