在TEXT文本框中只允许输入数字和小数点,如何实现?只能编程实现吗?

类别:VB语言 点击:0 评论:0 推荐:

在TEXT文本框中只允许输入数字和小数点,如何实现?只能编程实现吗?

 

Private Sub Text1_KeyPress(KeyAscii As Integer)
If (Chr(KeyAscii) > "9" Or Chr(KeyAscii) < "0") And Chr(KeyAscii) <> "." Then
    KeyAscii = 0
End If
End Sub

    回复人:y1g1y1(袁飞☆曾经沧海难为水,除却VB不是云☆) 


在keypress中进行判断,如果不合格就sendkeys(vb_backspace)
具体函数的参数我不太会写了,就是用sendkeys的 
 回复人:playyuer(女㊣爱) (2001-5-8 13:09:00)  得0分
Private Sub Text1_KeyPress(KeyAscii As Integer)
  Select Case KeyAscii
      Case Asc("-") '允许负数
            If Text1.SelStart = 0 Then
              If Left(Text1.Text, 1) = "-" Then
                  KeyAscii = 0
                  Beep
              End If
            Else
              KeyAscii = 0
              Beep
            End If
        Case 8
              '无变化,退格键不屏蔽
        Case Asc(" ") '32
            If Text1.SelLength = 0 Then
                KeyAscii = 0
            End If
        Case Asc(".") '46 '允许小数点
            If InStr(Text1.Text, ".") Then
                KeyAscii = 0
            End If
        Case Is < Asc(0) '48
              KeyAscii = 0
        Case Is > Asc(9) '57
              KeyAscii = 0
  End Select
End Sub 

 回复人:liu_feng_fly(一只菜鸟,忽忽悠悠的就飞来了!!)

 

本文地址:http://com.8s8s.com/it/it6615.htm