在vb编程中,怎么让文本框里只接受数字

来源:百度知道 编辑:UC知道 时间:2024/06/09 07:50:10

Dim a As String
Private Sub Form_Load()
a = ""
End Sub
Private Sub Text1_Change()
If IsNumeric(Text1.Text) Then
a = Text1.Text
Else
Text1.Text = a
End If
End Sub

'只接受数字和退格

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii > Asc("0") And KeyAscii < Asc("9") Or KeyAscii = 8 Then
Else
KeyAscii = 0
End If
End Sub