我想在TEXT.TEXT中只输入数子(包括小数点后两位含小数点)怎么写代码?
解决方案 »
- msflexgrid有选择输入问题?
- 高高高高手请进:用API函数mciSendString在自己的窗体Form1中播放视频图像,用GetTopWindow可以获得该图像窗口的句柄h2=GetTopWindow(For
- 请问有谁知道"水晶报表"怎么设置参数字段???
- VB+SQL Server:哪个数据控件比较好?另外,在VB里怎么知道现在有没有数据库正在打开?正在打开的又是什么数据库?
- 怎么在编好VB应用程序后,把所关联的SQL数据库带走!
- VB使用掃描儀的問題
- 如何获得当点击DATAGRID的标题栏的事件
- 如何使用Inet控件下载文件,如一个ZIP文件?
- 请教:想对Access数据库中的数据重新排序,该怎么实现啊!
- 多次应用recordset ,在每次应用后除了rs.close和set nothing还有别的办法吗?
- 关于Postmessage的lParam参数问题
- 网络通讯问题:如何把多次接受到数据合并后再触发处理数据的事件
1. 找个别的控件。
2. 自己在Change事件中写控制,每次改变的时候,如果不为数字就清除,即恢复修改前的原来的数字。
If KeyAscii <> 46 And Not (KeyAscii >= 48 And KeyAscii <= 57) Then
KeyAscii = 0
End If
End Sub
1,小数点可以输入很多,我只想输入一个就可以了;
2,我不能用去格(bk sp)键删除.
怎么办?
if trim(text1.text)<>"" then
if not isnumeric(text1.text) then
msgbox "请输入数值型数据!",48,"提示"
text1.setfocus
end if
end if
end sub
Private Sub Text1_Change()
With Text1
If InStr(1, StrReverse(.Text), ".") >= 4 Then
SendKeys "{BACKSPACE}"
End If
End With
End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)
With Text1
If KeyAscii = 46 Or (KeyAscii >= 48 And KeyAscii <= 57) Then
If Len(Trim(.Text)) <> 0 Then
If InStr(1, StrReverse(.Text), ".") > 0 And KeyAscii = 46 Then
KeyAscii = 0
End If
End If
End If
End With
End Sub
'// Check "."
If (KeyAscii = 46) Then
'// Ensure only one "."
If (InStr(1, Text1.Text, Chr(KeyAscii)) > 0) Then
KeyAscii = 0
End If
Exit Sub
End If
'// Check number "0-9"
If (KeyAscii >= 48 And KeyAscii <= 57) Then
Exit Sub
End If
'// Check Backspace key
If (KeyAscii = 8) Then
Exit Sub
End If
KeyAscii = 0
End Sub
Call Number(KeyAscii)
End SubPublic Sub Number(KeyAscii As Integer)
Dim strValid As String
strValid = "0123456789."
End Sub我们的现在就是这么做的。
Case 8, 9 13, &H30 To &H 39
Case Asc(".")
If InStr(Text1, ".") Then KeyAscii = 0
Case Else
KeyAscii = 0
End SelectEnd Sub