《VB程序设计-时间间隔改进.docx》由会员分享,可在线阅读,更多相关《VB程序设计-时间间隔改进.docx(4页珍藏版)》请在金锄头文库上搜索。
1、VB程序设计时间间隔改进(作者:草原飞狼 2014年6月5日)声明:仅供学习与交流使用,高手请飘过,谢谢!所有代码都是个人亲自编写并调试成功。布局运行界面(1)运行界面(2)运行界面(3)源代码如下:Rem 定义三个时间为变体类型:stime为开始时间,etime为结束时间,jtime为间隔时间Dim stime As VariantDim etime As VariantDim jtime As VariantDim s1, e1 As VariantPrivate Sub Command1_Click()Rem 启动按钮,计算时间差If Label4.Caption = And Label
2、5.Caption = Then MsgBox 没有输入开始和结束时间!, vbInformation, 错误提示 Command3.SetFocusElse jtime = etime - stime Label6.Caption = Format(jtime, hh:mm:ss)End IfEnd SubPrivate Sub Command2_Click()Rem 清空Label4.Caption = Label5.Caption = Label6.Caption = Command3.SetFocusEnd SubPrivate Sub Command3_Click()Rem 输入正确
3、的开始时间和结束时间,注意时间格式Rem 输入开始时间并判断其格式是否正确s1 = InputBox(请输入开始时间,注意时间格式!, 输入开始时间, 08:08:08)Do While IsDate(s1) = False MsgBox 输入时间格式不对,请重新输入!, vbInformation, 错误提示 s1 = InputBox(请输入开始时间,注意时间格式!, 输入开始时间, 08:08:08)LoopRem 输入结束时间并判断其格式是否正确e1 = InputBox(请输入结束时间,注意时间格式!, 输入结束时间, 10:10:10)Do While IsDate(e1) = F
4、alse MsgBox 输入时间格式不对,请重新输入!, vbInformation, 错误提示 e1 = InputBox(请输入开始时间,注意时间格式!, 输入开始时间, 10:10:10)Loopstime = CDate(s1) 转换成时间格式etime = CDate(e1) 转换成时间格式Label4.Caption = Format(stime, hh:mm:ss) format是格式函数,Format(stime, hh:mm:ss)表示按时分秒格式输出Label5.Caption = Format(etime, hh:mm:ss)Command1.SetFocusEnd SubPrivate Sub Command4_Click()Rem 退出Dim int_msg As Integerint_msg = MsgBox(单击“确定”退出,单击“取消”程序继续!, vbOKCancel + vbQuestion + vbDefaultButton2, 退出提示)If int_msg = vbOK Then Unload MeEnd IfEnd Sub4