Private Sub Form_Load() '控制界面大小 Me.Height = 5820 Me.Width = 7080 End Sub Private Sub Label_calculate_Click() '时间机算按钮 '清空时间记录 Label.Caption = "" '判断输入框的多种情况 If Text_bTime.Text = "" And Text_sTime.Text = "" Then MsgBox "您还没有输入时间,请输入时间!" '把光标移到开始时间的输入框 Text_bTime.SetFocus ElseIf Text_bTime.Text = "" And Text_sTime.Text <> "" Then If IsDate(Text_sTime.Text) = True Then MsgBox "您还没有输入开始时间,请输入!" '把光标移到开始时间的输入框 Text_bTime.SetFocus Else MsgBox "您还没有输入开始时间,请输入!并且截止时间格式错误,格式为:" & Now Text_bTime.SetFocus Text_sTime.Text = "" End If ElseIf Text_bTime.Text <> "" And Text_sTime.Text = "" Then If IsDate(Text_bTime.Text) = False Then MsgBox "您输入的开始时间不是时间格式,请输入时间格式,格式为:" & Now '清空输入框 Text_bTime.Text = "" '把光标移到开始时间的输入框 Text_bTime.SetFocus Else MsgBox "您没有输入截止时间,默认此时为截止时间。" '调用机算过程 Call r_Times End If ElseIf IsDate(Text_bTime.Text) = False And IsDate(Text_sTime.Text) = False Then MsgBox "您输入格式错误,格式如:" & Now '清空输入框 Text_bTime.Text = "" Text_sTime.Text = "" '把光标移到开始时间的输入框 Text_bTime.SetFocus ElseIf IsDate(Text_bTime.Text) = True And IsDate(Text_sTime.Text) = True Then '调用机算过程 Call j_Times ElseIf IsDate(Text_bTime.Text) = False And IsDate(Text_sTime.Text) = True Then MsgBox "您输入的开始时间有误,请重新输入!" Text_bTime.Text = "" Text_bTime.SetFocus ElseIf IsDate(Text_bTime.Text) = True And IsDate(Text_sTime.Text) = False Then MsgBox "您输入的截止时间有误,请重新输入!" Text_sTime.Text = "" Text_sTime.SetFocus Else MsgBox "您的输入有误,请重新输入!" '清空输入框 Text_bTime.Text = "" Text_sTime.Text = "" '把光标移到开始时间的输入框 Text_bTime.SetFocus End If End Sub Public Sub r_Times() '如果没有输入截止时间时,默认此时为截止时间 Label.Caption = "到此时相隔:" & DateDiff("yyyy",Text_bTime.Text,Now) & "年" & Chr(10) Label.Caption = Label.Caption & DateDiff("q",Now) & "季节" & Chr(10) Label.Caption = Label.Caption & DateDiff("m",Now) & "月" & Chr(10) Label.Caption = Label.Caption & DateDiff("ww",Now) & "周" & Chr(10) Label.Caption = Label.Caption & DateDiff("d",Now) & "天" & Chr(10) Label.Caption = Label.Caption & DateDiff("h",Now) & "小时" & Chr(10) Label.Caption = Label.Caption & DateDiff("n",Now) & "分钟" & Chr(10) Label.Caption = Label.Caption & DateDiff("s",Now) & "秒" End Sub Public Sub j_Times() '机算时间 Label.Caption = "相隔:" & DateDiff("yyyy",Text_sTime.Text) & "年" & Chr(10) Label.Caption = Label.Caption & DateDiff("q",Text_sTime.Text) & "季节" & Chr(10) Label.Caption = Label.Caption & DateDiff("m",Text_sTime.Text) & "月" & Chr(10) Label.Caption = Label.Caption & DateDiff("ww",Text_sTime.Text) & "周" & Chr(10) Label.Caption = Label.Caption & DateDiff("d",Text_sTime.Text) & "天" & Chr(10) Label.Caption = Label.Caption & DateDiff("h",Text_sTime.Text) & "小时" & Chr(10) Label.Caption = Label.Caption & DateDiff("n",Text_sTime.Text) & "分钟" & Chr(10) Label.Caption = Label.Caption & DateDiff("s",Text_sTime.Text) & "秒" & Chr(10) End Sub
用VB写的时间计算器。