跪求一段VB代码,textbox只能输入数字,小数点,以及退格,且小数点只能有一个

来源:百度知道 编辑:UC知道 时间:2024/07/07 16:56:28
跪求一段VB代码,textbox只能输入数字,小数点,以及退格,且小数点只能有一个
有的代码做完后可以把别的字符复制进去,我要连复制都复制不进去的

假如你的textbox的name为text1那么加入以下代码即可实现你要的功能。
Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 8
Case 46
If InStr(Text1, ".") <> 0 Then KeyAscii = 0
Case 47 To 57
Case Else
KeyAscii = 0
End Select
End Sub

Private Sub Text1_Change()
If Not IsNumeric(Text1.Text) Then Text1.Text = ""
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 46 Then
If InStr(1, Text1.Text, ".") <> 0 Then KeyAscii = 0
Else
If (Not IsNumeric(Chr(KeyAscii))) And KeyAscii = 6 Then KeyAscii = 0
End If
End Sub

复制无效,只能输数字,小数点,退格
完全符合你的要求了 呵呵 拿分,闪人 o(∩_∩)o...哈哈

'创建个窗体放个文本控件写如下代码

Dim svstr As String
Private Sub Form_Load()
svstr = ""
End Sub

Private Sub Text1_Change()
If I