时间计算器

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写的时间计算器。

相关文章

Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强制返回为文本 --------------------------...
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办法, Format 或者FormatDateTime 竟然结果和...
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace My ‘全局错误处理,新的解决方案直接...
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用的爽呀,这篇文章写与2011年,看来我以前没...
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选中的单元格进行处理 Dim m As Range, t...
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integ...