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

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 zht_ok 的 blog

在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(一只菜鸟,忽忽悠悠的就飞来了!!)

 

本文关键:限制text
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top