资源预览内容
第1页 / 共4页
第2页 / 共4页
第3页 / 共4页
第4页 / 共4页
亲,该文档总共4页全部预览完了,如果喜欢就下载吧!
资源描述
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 Label5.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 输入正确的开始时间和结束时间,注意时间格式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) = False 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
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号