又来麻烦大家不好意思!!!

wangqiu 2003-08-22 04:27:34
如何控制在一个文本框输入的数据类型不错,

例如,我添加text1.text,然后我想在text1.text必须输入数字,而输入字符的时候不允许。
...全文
33 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangqiu 2003-08-22
  • 打赏
  • 举报
回复
对不起了,分太少了
道素 2003-08-22
  • 打赏
  • 举报
回复

Private Sub Text1_KeyPress(KeyAscii As Integer)
If Not IsNumeric(Chr(KeyAscii)) Then KeyAscii = 0
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)


Select Case KeyAscii
Case 48 To 57
Case 8
Case Else
Beep
MsgBox "error!"
KeyAscii = 0
End Select


Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long


Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Const ES_NUMBER = &H2000
Private Const GWL_STYLE = -16

Private Sub ForceNumeric(Box As TextBox)
On Error Goto Catch
Dim nStyle As Long
nStyle = GetWindowLong(Box.hWnd, GWL_STYLE)
Call SetWindowLong(Box.hWnd, GWL_STYLE, nStyle Or ES_NUMBER)
Goto Finally
Catch:
Call MsgBox(Err.Description, vbCritical Or vbOKOnly, "Error")
Finally:
End Sub
viena 2003-08-22
  • 打赏
  • 举报
回复
Private Sub Text1_Validate(Cancel As Boolean)
if text1.text<>"" then
if not isnumeric(text1.text) then
cancel=true
end if
end if
End Sub
xayzmb 2003-08-22
  • 打赏
  • 举报
回复
Private Sub Text1_Change()
If IsNumeric(Text1.Text) = False Then
MsgBox "请输入数字"
End If
End Sub
饮水需思源 2003-08-22
  • 打赏
  • 举报
回复
'数值型判断:isnumeric(text1.text)
'日期型判断:isdate(text1.text)

private sub text1_lostfocus()
if text1.text<>"" then
if not isnumeric(text1.text) then
msgbox "请输入数值型数据!",48,"提示"
text1.setfocus
exit sub
end if
end if
end sub

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧