大连体育场附近酒店:vb6.0问题

来源:百度文库 编辑:高考问答 时间:2024/04/29 23:44:03
怎么限制TextBox控件里限制使用者键入的值
比如只准输入数字
比如可以输入汉字和英语字母,不可以输入数字等

isnumeric true 表明是数字 false 表明不是数字
Private Sub Command1_Click()
If IsNumeric(Text1.Text) = False Then
Text1.Text = ""
End If
End Sub

仅限输入数字:
If IsNumeric(Text1.Text) = False Then
Text1.Text = Val(Text1.Text)
MsgBox "Number only!"
Exit Sub
End If
仅限汉字和英文:
For i = 1 To Len(Text1.Text)
If Asc(Mid(Text1.Text, i, 1)) >= 48 And Asc(Mid(Text1.Text, i, 1)) <= 57 Then
MsgBox "No number!"
Text1.Text = ""
Exit Sub
End If
Next

可以在
private sub text1_change()
………… '在这里输入限制的程序
end sub