怎么样才能最多只能输入一个小数点??
我是要输入单精度的数字,只让输入数字和小数点已经处理了,可是点的个数不知道怎么控制了

解决方案 »

  1.   

    Private Sub Text2_KeyPress(KeyAscii As Integer)
        If InStr(Text2.Text, ".") <> 0 And KeyAscii = 46 Then KeyAscii = 0
    End Sub问题解决~~
      

  2.   

    在处理之前加入idnumeric(text2)进行判断一下
      

  3.   

    Option Explicit
    Dim decimaltag As BooleanPrivate Sub Form_Load()
       decimaltag = False
    End SubPrivate Sub Text1_Change()
       If InStr(1, Trim$(Text1.Text), ".") Then
          decimaltag = True
       End If
    End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)
       If KeyAscii = 46 And decimaltag = False Then
          decimaltag = True  '控制小数点只能输入一次。
       ElseIf KeyAscii >= vbKey0 And KeyAscii <= vbKey9 Then
          Exit Sub
       ElseIf KeyAscii <= 31 Then
          Exit Sub   '控制可接受退格键或删除键等。
       Else
          KeyAscii = 0
       End If
    End Sub
      

  4.   

    你可以把你输入的数格式化一下呀!
    如: text1.text=format(text1.text,"0.0")
    就是把输入的数据只保留一位小数。