private sub text1_keypress(keyascii as integer)
 if keyascii<48 or keyascii>57 then
  keyascii=0
text1.setfocus
end if

解决方案 »

  1.   

    以下代码写在KeyPress事件中
    If (KeyAscii < Asc("0") Or KeyAscii > Asc("9")) And KeyAscii <> 8 And KeyAscii <> 13 And KeyAscii <> Asc(".") Then
          KeyAscii = 0
      End If
      

  2.   

    Private Sub text1_KeyPress(KeyAscii As Integer)
     If Not (KeyAscii > 47 And KeyAscii < 58 Or KeyAscii = 13 Or KeyAscii = 8 Or KeyAscii = 46) Then KeyAscii = 0
     End Sub以上只能输入数字和小数点
      

  3.   

    之能够在KeyPress而不能够在KeyDown或者KeyUp中使用.
      

  4.   

    用KEYCODE 检测传回的ASC值.同上.
    必须是数字可以用函数ISNUMRIC(text1.text)返回值是否为true
      

  5.   

    使用Masked Edit控件!
    ================================================================
         靠,各位兄弟这么有才华,我...我..............5555555555555555