想实现的功能 :窗体上有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然后触发触发事件?等等
如: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然后触发触发事件?等等
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
你先把原来的数据转换好了再写吧。建议ISDATE
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