Private Sub Text1_KeyPress(KeyAscii As Integer)
If Not (KeyAscii >= Asc("0") And KeyAscii <= Asc("9")) Then
KeyAscii = 0
End If
End Sub
If Not (KeyAscii >= Asc("0") And KeyAscii <= Asc("9")) Then
KeyAscii = 0
End If
End Sub
解决方案 »
- VB中 5个TEST 控件 在第1个输入例如: 12345 那么第一个只显示1 第2个中只显示2 依次类推 请问如何编写?
- 请问VB可以使一个控件Frame1变为透明吗??请教高手!! 在线等答案 马上送分!
- 求教!用FSO遍历文件夹的问题
- 关于PowerPoint的宏
- 请问 SQL SERVER 7.0 中的数据库怎么还原到 SQL2000 中?急 。。。。。
- 50分求助 帮忙看一个函数
- 用winsock编写的服务端同时接受几百个客户端发送的数据会丢失文件吗??
- 请问如果用VB解决这个问题?
- 我写了个ocx,有个ViewPath属性,怎样可以实现在设计阶段,出现CommonDialog1.ShowOpen的界面?
- 建议在“扩充话题”里加一个“结分讨论”
- mscomm控件
- 谁有使用vb自带的报表设计器,进行打印的例子,给代码,马上给分,在线等
If KeyAscii = vbKeyReturn Then
If Del_Space(txtZYHM.Text) = "" Then
MsgBox "对不起,住院号码不能够为空!", vbOKOnly, Me.Caption
Exit Sub
End If
ElseIf (KeyAscii < 48 Or KeyAscii > 57) And (KeyAscii < 8 Or KeyAscii > 13) Then
KeyAscii = 0
End If
End Sub
If Not IsNumeric(Text1.Text) Then
MsgBox "请输入数字", vbOKOnly + vbInformation, "输入错误"
Text1.SetFocus
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End If
End Sub
回复人: chewinggum(口香糖) ( ) 信誉:100 2002-12-17 16:27:00 得分:0
用isNumeric函数判断是否为数值更简单,上面两位好像都没考虑到小数问题,用这个函数就一劳永逸了
Select Case X
Case 8, Asc("."), Asc("0") To Asc("9")
Dec_Only = X
Case 13
Dec_Only = 9
Case Asc("。")
Dec_Only = Asc(".")
Case Else
Dec_Only = 0
End Select
End Function引用例子:
Private Sub text1_KeyPress(KeyAscii As Integer)
KeyAscii = Dec_Only(KeyAscii)
End Sub