想实现的功能 :窗体上有text1和text2两个文本框,在text1.text中输入年月日,
如:050217 ,当按tab键,或enter键,或是用鼠标点,当使光标从text1跳到text2时,判断,月和日是否正确? 要求01<月<12 并且01<日<31  ..如果正确,则继续,如果月日输入有错误.则让text1.text=””,让光标退回text1.判断月日是否正确的函数我已经写出来了. Private Function test_txt1() As Boolean   ‘判断月日是否正确
 Dim txt1data As Integer
 Dim txt1day As Integer
 Dim txtmonth As Integer
  txt1data = Text1.Text
 txt1day = txt1data Mod 1000 Mod 100
 txtmonth = txt1data Mod 1000 - txt1day
 If txt1day < 1 Or txt1day > 31 Or txt1month < 1 Or txt1month > 12 Then
   test_txt1 = False
 Else
   test_txt1 = True
 End If
End Function
关键是其他功能如何实现?怎么判断光标离开text1然后触发触发事件?等等

解决方案 »

  1.   

    用isdate函数判断输入值是否为日期型数据吧
    private text1_lostfocus()
        if trim(text1.text)<>"" then
            if not isdate(text1.text) then
                msgbox "请输入日期型数据!",48,"提示"
                text1.text=""
                text1.setfocus
                exit sub
            else
                text1.text=format(text1.text,"YYYY-MM-DD")
            end if
        end if
    end sub
      

  2.   

    isdate("20" & left(text1,2) & "/" & mid(text1,3,2) & "/" & mid(text1,5,2))
      

  3.   

    为什么不用DTPicker控件呢?那个控件有个自定义格式(CustomFormat属性),可以以你想要形势显示,干吗要非要用text?
      

  4.   

    2097也是别人的错?
    你先把原来的数据转换好了再写吧。建议ISDATE
      

  5.   

    昏过去,为什么要把年月日分开来啊,用MSK不就好了
      

  6.   

    Private Sub Text1_LostFocus()
    Dim TEMP As String
    TEMP = Left(Text1.Text, 2) + "年" + Mid(Text1.Text, 3, 2) + "月" + Right(Text1.Text, 2) + "日"
    TEMP = Format(TEMP, "LONG date")
    Print TEMP
    If IsDate(TEMP) <> True Then
    Print "日期输入错误,请从新输入。"
    Text1.SetFocus
    End If
    End Sub