如题

解决方案 »

  1.   

    没太明白,是不是这个意思Private Sub Text1_LostFocus()
        
        If IsNumeric(Text1.Text) Then
            Text1.Text = Format(CLng(Text1.Text), "00000000")
        End If
        
    End Sub
      

  2.   

    if isnumeric(text1) and len(text1)=8 then
       msgbox "有效"
    end if
      

  3.   

    也就是我有一个text box,有一个long型的变量需要从这个text box里取值。如果在text box里输入的数的位数不等于8,就提示输入错误,比如输入22234时,或输入999999999,提示错误(因为22234这个数只有5位,而999999999有9位)。
      

  4.   

    奥,明白乐,用这个吧
    if len(textbox1.text)=8 then 
        .......
    else
        msgbox "有误"
    end if
    前提是必须先判断是否为数字,可以使用IsNumeric函数判断
      

  5.   

    谢谢毛毛虫!还有一个类似的问题,比如如果一个date型的变量要从text box取值,怎么保证用户必须按2004-1-19这样的格式输入?
      

  6.   

    If IsDate(Text1.Text) Then
            Text1.Text = Format(Text1.Text, "YYYY-MM-DD")
        End If