vb控制TEXT的值

来源:百度知道 编辑:UC知道 时间:2024/05/13 23:36:59
我想自己做一个闹钟,有点问题不知怎么解决,问题就是TEXT的输入问题.请问各位大虾,我想把TEXT.TEXT的值写成只能输入0-9的数字,其它的任何符号,小数点,英文字母都不能输入,能做到吗?最好可以简单点,本人学VB不久,谢啦~~~

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

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii < 48 Or KeyAscii > 57 Or Len(Text1) = 1 Then
If KeyAscii <> 8 Then
KeyAscii = 0
End If
End If
End Sub

dim tx as string = Text.Text
dim ti as Integer
if Integer.tryParse(tx,ti) = true then
if ti < 0 or ti > 9 then
else
messageBox.show("提示消息")
end if
else
messagebox.Show("不是数字")
end if

Private Sub Command1_Click()

Text1.Text = Val(Text1.Text)

a = Text1.Text
If a < 0 Then Text1.Text = ""
If a > 9 Then Text1.Text = ""
End Sub

Private Sub Command1_Click()
a= Val(T