lostfocus中
text1.text=format(text1.text,"yyyy\/mm\/dd")

解决方案 »

  1.   

    1.使用maskedit
    2.通过程序实现
        比如在lostfocus事件中添加代码
    3.自己做一个控件来实现
      

  2.   

    textbox好像不行,可以使用maskedbox这个控件,把mask属性设为####-##-##即可。
      

  3.   

    参考Format
    SET DATE [TO] AMERICAN | ANSI | BRITISH | FRENCH | GERMAN
    | ITALIAN | JAPAN | TAIWAN | USA | MDY | DMY | YMD
    | SHORT | LONG其中ITALIAN代表dd-mm-yy 
      

  4.   

    一个笨方法,不过还有效
    Private Sub Command1_Click()Dim strtemp As String
    Dim a As Stringa = Mid$(Text1.Text, 1, 4) + "-"
    strtemp = a
    a = Mid$(Text1.Text, 5, 2) + "-"
    strtemp = strtemp + a
    a = Mid$(Text1.Text, 7, 2)
    strtemp = strtemp + a
    MsgBox strtemp
    End Sub
      

  5.   

    Private Sub Text1_Change()
        Dim strTemp As String
        If Len(Text1.Text) < 8 Then Exit Sub
        strTemp = Mid(Text1.Text, 1, 4) & "-" & Mid(Text1.Text, 5, 2) & "-" & Mid(Text1.Text, 7, 2)
        If IsDate(strTemp) Then Text1.Text = strTemp
        Text1.SelStart = Len(Text1.Text)
    End Sub
      

  6.   

    写错了
    Option ExplicitPrivate Sub Text1_Change()
        Dim strTemp As String
        If Len(Text1.Text) < 8 Then Exit Sub
        strTemp = Mid(Text1.Text, 1, 4) & "-" & Mid(Text1.Text, 5, 2) & "-" & Mid(Text1.Text, 7, 2)
        If IsDate(strTemp) Then
            Text1.Text = strTemp
            Text1.SelStart = Len(Text1.Text)
        End If
    End Sub
      

  7.   

    sorry我没有注意,海军上校的做法是对的我的办法必须是这样的字符2002-01-01sorry
      

  8.   

    to 小山兄
    是阿,我最开始就使用format
    不过发现好像行不通,采用哪个笨方法,不知道有没有更好的方法实现
      

  9.   

    谢谢各位了!明白得很透彻。不过,再问一个,maskedbox是第3方的还是vb里有的?如果是第3方控件请问在哪里下载呢,谢谢!
    我的email是[email protected]
      

  10.   

    dowm free 的意见不错,我和他的观点一样。
      

  11.   

    to daryl715(海军少校) (我给你连升三级,哈哈,值得把!     -----楼主,借你的地盘回复,没有意见巴!
      

  12.   


    楼主:我给各思路1:判断是否是数值(如20020101)
    2:判断长度(yymmdd or yyyymmdd)
    3:截取字符,构成日期
      

  13.   

    Maskedbox是微软自带的一个控件----Microsoft Masked Edit Control 6.0
      

  14.   

    Maskedbox是微软自带的一个控件----Microsoft Masked Edit Control 6.0