银色北伐军徽记:VB编程问题

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/28 14:10:50
怎么使输入框里,也就是控件text,里面只能输入数字,不能输入英文?

Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case Asc("0") To Asc("9"), vbKeyBack
'nop
Case Else
KeyAscii = 0
End Select
End Sub

IF语句,如果不是0,1,2,3,4,5,6,7,8,9,0就重新执行。

if not(isnumberic(text1.text)) then
msgbox "只能输入数字",16+48,"提示"
end if

msgbox "只能输入数字",16+48,"提示"
end if 就可以了

只需要把内容转换为数值型就可以了
如val(text1.text)

if not(isnumeric(text1.text)) then
msgbox "必须输入数字"
exit sub
end if