VB倒计时代码

就是点开按纽后弹出一个30秒的到计时框
求高手帮忙写下

第1个回答  推荐于2016-10-09
放置两个command(一个叫做cmdDel,另一个叫做cmdAdd)和一个Timer(叫做tmrDJS)
窗体的StartUpPosition属性设为2 - CenterScreen

并添加以下代码:

Private Sub cmdAdd_Click()
Dim sName As String, AllNum As Integer, TerminateDate As Date
sName = InputBox("倒计时的名字?")
TerminateDate = InputBox("截止时间?例如2009-10-20 3:23:19")
AllNum = GetSetting("倒计时", "倒计时列表", "倒计时总数", "0")
AllNum = AllNum + 1
SaveSetting "倒计时", "倒计时列表", "倒计时总数", AllNum
SaveSetting "倒计时", "倒计时列表", "时间" & Trim(Str(AllNum)), TerminateDate
SaveSetting "倒计时", "倒计时列表", "名字" & Trim(Str(AllNum)), sName
MsgBox "添加成功!", vbInformation
End Sub

Private Sub cmdDel_Click()
Dim Qx As Integer
Qx = InputBox("列表中的几个?")
Dim sDate As String, sName As String, AllNum As Integer, Qu As Integer
AllNum = GetSetting("倒计时", "倒计时列表", "倒计时总数", "0")
For i = 1 To AllNum
sDate = GetSetting("倒计时", "倒计时列表", "时间" & Trim(Str(i)), "0")
sName = GetSetting("倒计时", "倒计时列表", "名字" & Trim(Str(i)), "0")
If sDate <> "0" Then
Qu = Qu + 1
If Qu = Qx Then
If MsgBox("是要删除倒计时 " & sName & " 吗?", vbYesNo + vbQuestion) = vbYes Then
SaveSetting "倒计时", "倒计时列表", "时间" & Trim(Str(i)), "0"
End If
Exit For
End If
End If
Next i
End Sub

Private Sub Form_Load()
Height = 3570
Width = 5550
Caption = "倒计时"
tmrDJS.Interval = 500
cmdAdd.Left = 4200
cmdAdd.Top = 2520
cmdAdd.Height = 255
cmdAdd.Width = 1215
cmdAdd.Caption = "添加倒计时"
cmdDel.Left = 4200
cmdDel.Top = 2760
cmdDel.Height = 255
cmdDel.Width = 1215
cmdDel.Caption = "删除倒计时"
End Sub

Private Sub tmrDJS_Timer()
Cls
Dim DJS As Date, sDate As String, sName As String, AllNum As Integer, Printed As Boolean
Dim Kd As Double
AllNum = GetSetting("倒计时", "倒计时列表", "倒计时总数", "0")
For i = 1 To AllNum
sDate = GetSetting("倒计时", "倒计时列表", "时间" & Trim(Str(i)), "0")
sName = GetSetting("倒计时", "倒计时列表", "名字" & Trim(Str(i)), "0")
If sDate <> "0" Then
DJS = sDate
If DJS - Now <= 0 Then
Print sName; " 已经到了!"
Else
Kd = DJS - Now
Print "距离 "; sName; " 还有 ";
Print Int(Kd); " 天 ";
Kd = Kd - Int(Kd)
Print Int(Kd * 24); " 小时";
Kd = Kd - Int(Kd * 24) / 24
Print Int(Kd * 24 * 60); " 分钟";
Kd = Kd - Int(Kd * 24 * 60) / 24 / 60
Print Int(Kd * 24 * 60 * 60 + 0.5); " 秒"
End If
Printed = True
End If
Next i
If Not Printed Then Print "列表为空!"
End Sub

然后运行即可~
第2个回答  2010-08-12
QQ我124493778,我给你发一个。代码很详细 ,也很简单明了本回答被提问者采纳
第3个回答  2010-08-12
用Timer控件

VB倒计时功能,要求在text里显示剩余,格式oo:00:00
1. Dim t As Double 2. Private Sub Command1_Click()3. Label1.Caption = "现在开始倒计时"4. t = Val(Text1.Text) * 60 5. Timer1.Enabled = True 6. Text1.Text = Format(t \\ 3600, "00:") & Format(((t + 1) Mod 3600) \\ 60, "00:") & Format(t Mo...

如何用VB程序设计出倒计时(编程)
`Timer1_Timer`事件循环更新时钟和倒计时。每3秒校准一次时钟,并更新`sum_zj`值。同时,当`sum_zj1`的值为正数且`sum_zj`大于等于3时,会递减`sum_zj1`的值。当`sum_zj1`变为零或负数时,将改变窗口背景色为红色,并禁用定时器。通过调整示例代码中的`sum_zj1`变量,您可以轻松实现不同时间...

求助:vb中到到某一天的倒计时(精确到秒)
在窗体上添加一个Label控件和一个Timer控件,然后将以下代码粘贴到代码窗口中,即可实现到某一天的倒计时功能(精确到秒)。在代码中定义了一个常量OneDay,用于指定目标时间,格式为月\/日\/年。在Form_Load事件中,为Timer控件设置间隔为1000毫秒(即一秒),并启用Timer控件。在Timer控件的Timer事件处理程...

VB如何实现倒计时?
7、双击窗体,进入代码编辑器,在 Form_Load事件中写入代码:Timer1.Enabled = False '先关闭计时器。8、关闭代码窗口,按下F5运行程序,单击“设置倒计时”命令按钮,弹出输入对话框,此时输入分钟数为1,确定。9、单击“启动倒计时”命令按钮,文本框显示倒计时时间,并时刻变动,至此实现了倒计时功能。

求VB时钟倒计时代码
本代码实现了一个简单的VB时钟倒计时功能。用户可以通过输入框输入倒计时秒数,然后点击按钮启动倒计时。在按钮点击事件处理程序中,首先从输入框获取用户输入的倒计时秒数,并将其赋值给变量n。接着,将label控件的文本设置为n,显示当前倒计时值。然后,将计时器的间隔设置为1000毫秒(即1秒),并开启...

vb倒计时代码
Label1 = "倒计时: " & s & "秒"End Sub Private Sub Timer1_Timer()s = s - 1 Label1 = "倒计时: " & s & "秒"If s <= 0 Then Timer1.Enabled = False cmdStart.Caption = "启动时间"cmdStart.TabIndex = 0 End If cmdStart.Enabled = s > 0 cmdStop.Enabled = s >...

倒计时vb代码
十秒倒计时程序代码:Dim N As Integer Private Sub Form_Load()N = 10 Timer1.Interval = 1000 Timer1.Enabled = True End Sub Private Sub Timer1_Timer()N = N - 1 If N > 0 Then Label1.Caption = N Else Label1.Caption = "时间到"Timer1.Enabled = False End If End Sub ...

vb用timer倒计时到0程序停止
在 VB 中使用 Timer 控件来实现倒计时功能很简单,你可以按照以下步骤进行编写:添加 Timer 控件到窗体中,设置它的 Interval 属性为 1000(表示以毫秒为单位的计时器间隔)。在窗体的 Load 事件中初始化倒计时的初始值:Private Sub Form_Load()Label1.Caption = "10"End Sub 这里将倒计时的初始值...

vb中倒计时的设计并在窗体中显示出来(比如100秒)
在窗体上画两个label控件,一个Command控件,一个Timer控件,代码如下:Dim Time_Num As Double '定义用于用户输入定时的初始值 Private Sub Command1_Click() '开始定时按钮 If Command1.Caption = "倒计时开始" Then '判断是否为开始,是则提示输入初始值,同时将按钮改成停止 Time_Num = ...

vb倒计时牌代码
Timer1.Enabled = Not Timer1.Enabled i = 0 End Sub Private Sub Form_Load()Timer1.Enabled = False Timer1.Interval = 1000 Command1.Caption = "开始计时"Text1 = ""End Sub Private Sub Timer1_Timer()If Text1 = "" Then Exit Sub Cls If Val(Text1) - i = 0 Then Print "...

相似回答