在一个textbox空间中该如何控制,比如说我输入了个数79.999999,而我只要79.99。那该如果操作???

解决方案 »

  1.   

    原理不难
    就是判断算法比较麻烦(要考虑很多情况)Sub text1_keypress(……)
        dim s as string
        dim p as long
        
        if keyascii = vbkeyback then exit sub
        
        with text1
            s=.text
            p=instr(1, s, ".")
            if p>0 then
                if len(s)-p>=2 then
                    if .selstart>p then
                        if .sellenght=0 then
                            keyascii = 0
                        end if
                    end if
                end if
            end if
        end with
    end sub
      

  2.   

    Private Sub Text1_Validate(Cancel As Boolean)
        Text1.Text = Format(Text1.Text, "###0.00")
    End Sub