| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 392 人关注过本帖, 1 人收藏
标题:VB 建立一个指定时间的倒计时器
只看楼主 加入收藏
kuugaangela
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2014-5-11
结帖率:0
收藏(1)
已结贴  问题点数:20 回复次数:3 
VB 建立一个指定时间的倒计时器
想建立一个倒计时器
程序代码:
Dim nYear As Long, nDay As Long, tYear As Long, tDay As Long
Dim nSec As Long, tSec As Long
Dim strNow1 As String, strNow2 As String
Dim strEnd1 As String, strEnd2 As String
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
Sub showDay()
Text3.Caption = (tDay - nDay) Mod 365
End Sub
Sub showSecond()
nSec = 86400 - nSec + tSec
If nSec > 86400 Then
    nSec = nSec - 86400
    nDay = nDay + 1
End If
Text6.Caption = nSec
End Sub
Private Sub Command3_Click()
End
End Sub
Private Sub Form_Load()
strEnd1 = Text1
strEnd2 = Text2
tYear = Val(Right(Text1, 4))
tDay = (Val(Left(Text1, 2)) - 1) * 30 + Val(Mid(Text1, 2))
tSec = Val(Left(Text2, 2)) * 3600 + Val(Mid(Text2, 4, 2)) * 60 + Val(Right(Text2, 2))
End Sub

Private Sub Timer1_Timer()
strNow1 = Format(Now, "mm/dd/yyyy")
strNow2 = Format(Now, "hh:mm:ss")
nYear = Val(Right(strNow1, 4))
If nYear Mod 4 = 0 And nYear Mod 100 <> 0 Or nYear Mod 400 = 0 Then

 nDay = 366 - (Val(Left(strNow1, 2) - 1) * 30 + Val(Mid(strNow1, 4, 2)))
Else

 nDay = 365 - (Val(Left(strNow1, 2) - 1) * 30 + Val(Mid(strNow1, 4, 2)))
End If
nSec = Val(Left(strNow2, 2)) * 3600 + Val(Mid(strNow2, 4, 2) - 1) * 60 + Val(Right(strNow2, 2))
showSecond
showDay
showYear
End Sub


图片附件: 游客没有浏览图片的权限,请 登录注册

但是做了一半就不会做,不知道怎样做下去

[ 本帖最后由 kuugaangela 于 2014-6-3 17:17 编辑 ]
2014-06-03 17:16
xzlxzlxzl
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:湖北
等 级:贵宾
威 望:125
帖 子:1091
专家分:5825
注 册:2014-5-3
收藏
得分:20 
没那么复杂吧,下面代码简单解决
图片附件: 游客没有浏览图片的权限,请 登录注册


Private Sub Command1_Click()
  If Not IsDate(Text1) Or Not IsDate(Text2) Then
    MsgBox "日期格式错误,请检查"
    Exit Sub
  End If
  Timer1.Enabled = True
  Command1.Enabled = Timer1.Enabled Xor True
End Sub

Private Sub Form_Load()
  Text1 = DateAdd("d", 100, Date)
  Text2 = "8:00"                        '按100天初始化比较日期
  Timer1.Interval = 1000
  Timer1.Enabled = True
  Command1.Enabled = Timer1.Enabled Xor True
End Sub

Private Sub Text1_Change()
  Timer1.Enabled = False
  Command1.Enabled = Timer1.Enabled Xor True
End Sub

Private Sub Text2_Change()
  Timer1.Enabled = False
  Command1.Enabled = Timer1.Enabled Xor True
End Sub

Private Sub Timer1_Timer()
  Dim i As Long, d As Date, dd As Integer, h As Integer, m As Integer, s As Integer
  d = Text1 & " " & Text2
  i = DateDiff("s", Now, d)
  s = i Mod 60
  i = i \ 60
  m = i Mod 60
  i = i \ 60
  h = i Mod 24
  dd = i \ 24
  Label1.Caption = "距离" & d & "还有:" & dd & "日" & h & "小时" & m & "分" & s & "秒"
End Sub
2014-06-03 19:18
adffdda
Rank: 2
等 级:论坛游民
帖 子:98
专家分:15
注 册:2015-1-6
收藏
得分:0 
回复 2楼 xzlxzlxzl
你好,想在窗体上搞个倒计时,窗体添加个标签,标签数字从10秒到1秒窗体自动关闭
2017-02-05 20:58
adffdda
Rank: 2
等 级:论坛游民
帖 子:98
专家分:15
注 册:2015-1-6
收藏
得分:0 
回复 2楼 xzlxzlxzl
帮个忙?
2017-02-05 20:58
快速回复:VB 建立一个指定时间的倒计时器
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.039365 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved