
VB倒计时程序
运行效果如图(随手画的http://hi.baidu.com/%D7%F3%C6%B2%D7%D3%BE%DE%D1%C0%BA%A3%C3%F1/album/item/...
运行效果如图(随手画的 http://hi.baidu.com/%D7%F3%C6%B2%D7%D3%BE%DE%D1%C0%BA%A3%C3%F1/album/item/8df15982a43527e80e244462.html# ) 运行时单击 设置按钮 弹出InputBox输入框供用户输入倒计时的时间(单位为分钟)。 单击开始则在文本框内显示剩余时间数(时:分:秒格式),同时滚动条上的滚动块随时间自左向右移。
请给我代码 给我代码追加100分。 !!! 展开
请给我代码 给我代码追加100分。 !!! 展开
3个回答
展开全部
窗体上放一个label,一个HScrollbox,三个Commandbutton,一个timer
双击窗体,删掉别的代码,粘贴下面代码:
Dim Minute, Second As Long
Private Sub Command1_Click()
Minute = InputBox("输入分钟数", "倒计时时间")
Second = 60 * Minute
Label1.Caption = "倒计时时间为" & Minute & "分钟"
Command2.Enabled = True
Command3.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Private Sub Command3_Click()
Timer1.Enabled = False
Label1.Caption = "已结束倒计时"
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
Command2.Enabled = False
Command3.Enabled = False
End Sub
Private Sub Timer1_Timer()
If Second < 0 Then
Timer1.Enabled = False
Else
Label1.Caption = IIf(Second \ 3600 = 0, "00", IIf(Second \ 3600 < 10, "0" & Second \ 3600, Second \ 3600)) & ":" & IIf(Second \ 60 Mod 60 = 0, "00", IIf(Second \ 60 Mod 60 < 10, "0" & Second \ 60 Mod 60, Second \ 60 Mod 60)) & ":" & IIf(Second Mod 60 Mod 60 = 0, "00", IIf(Second Mod 60 Mod 60 < 10, "0" & Second Mod 60 Mod 60, Second Mod 60 Mod 60))
HScroll1.Value = (60 * Minute - Second) / (60 * Minute) * HScroll1.Max
Second = Second - 1
End If
End Sub
双击窗体,删掉别的代码,粘贴下面代码:
Dim Minute, Second As Long
Private Sub Command1_Click()
Minute = InputBox("输入分钟数", "倒计时时间")
Second = 60 * Minute
Label1.Caption = "倒计时时间为" & Minute & "分钟"
Command2.Enabled = True
Command3.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Private Sub Command3_Click()
Timer1.Enabled = False
Label1.Caption = "已结束倒计时"
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
Command2.Enabled = False
Command3.Enabled = False
End Sub
Private Sub Timer1_Timer()
If Second < 0 Then
Timer1.Enabled = False
Else
Label1.Caption = IIf(Second \ 3600 = 0, "00", IIf(Second \ 3600 < 10, "0" & Second \ 3600, Second \ 3600)) & ":" & IIf(Second \ 60 Mod 60 = 0, "00", IIf(Second \ 60 Mod 60 < 10, "0" & Second \ 60 Mod 60, Second \ 60 Mod 60)) & ":" & IIf(Second Mod 60 Mod 60 = 0, "00", IIf(Second Mod 60 Mod 60 < 10, "0" & Second Mod 60 Mod 60, Second Mod 60 Mod 60))
HScroll1.Value = (60 * Minute - Second) / (60 * Minute) * HScroll1.Max
Second = Second - 1
End If
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?

2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图...
点击进入详情页
本回答由AiPPT提供
展开全部
Dim a As Long
Private Sub Command1_Click()
a = Val(InputBox("请输入数值")) * 60
HScroll1.Max = a
HScroll1.Value = 0
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Text1.Text = Format(Str(a \ 3600) + ":" + Str(a \ 60 - (a \ 3600) * 60) + ":" + Str(a - (a \ 60) * 60), "hh:mm:ss")
HScroll1.Value = HScroll1.Max - a
If a = 0 Then
Timer1.Enabled = False
End If
a = a - 1
End Sub
运行通过,忘说了,控件就你画的,外加一个timer1,设其enable=false,inteval=1000
Private Sub Command1_Click()
a = Val(InputBox("请输入数值")) * 60
HScroll1.Max = a
HScroll1.Value = 0
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Text1.Text = Format(Str(a \ 3600) + ":" + Str(a \ 60 - (a \ 3600) * 60) + ":" + Str(a - (a \ 60) * 60), "hh:mm:ss")
HScroll1.Value = HScroll1.Max - a
If a = 0 Then
Timer1.Enabled = False
End If
a = a - 1
End Sub
运行通过,忘说了,控件就你画的,外加一个timer1,设其enable=false,inteval=1000
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
VERSION 5.00
Begin VB.Form Form1
BorderStyle = 1 'Fixed Single
Caption = "Form1"
ClientHeight = 2400
ClientLeft = 45
ClientTop = 375
ClientWidth = 4635
LinkTopic = "Form1"
MaxButton = 0 'False
ScaleHeight = 2400
ScaleWidth = 4635
StartUpPosition = 3 '窗口缺省
Begin VB.Timer Timer1
Left = 1320
Top = 1920
End
Begin VB.CommandButton Command3
Caption = "结束"
Height = 375
Left = 3375
TabIndex = 4
Top = 1800
Width = 855
End
Begin VB.CommandButton Command2
Caption = "开始"
Height = 375
Left = 1875
TabIndex = 3
Top = 1800
Width = 855
End
Begin VB.CommandButton Command1
Caption = "设置"
Height = 375
Left = 375
TabIndex = 2
Top = 1800
Width = 855
End
Begin VB.HScrollBar HScroll1
Height = 375
Left = 360
TabIndex = 1
Top = 1320
Width = 3975
End
Begin VB.Label Label1
BeginProperty Font
Name = "宋体"
Size = 48
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 975
Left = 360
TabIndex = 0
Top = 240
Width = 3855
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim countdown As Long
Dim timeleft As Long
Dim StartTime As Date
Dim NowTime As Date
Private Sub Command1_Click()
Dim countstr As String
Do
countstr = InputBox("请输入倒计时分钟数(1~1440)!")
Loop While Not IsNumeric(countstr) Or Val(countstr) < 0 Or Val(countstr) > 1440
countdown = Int(Val(countstr) * 60)
timeleft = countdown
Call ShowTime
End Sub
Private Sub Command2_Click()
Timer1.Interval = 500
StartTime = Now
NowTime = StartTime
Call ShowTime
Call Timer1_Timer
End Sub
Private Sub Command3_Click()
Unload Me
End Sub
Private Sub Form_Load()
countdown = 0
timeleft = 0
Call ShowTime
End Sub
Private Sub ShowTime()
Dim hourstr As Integer
Dim minutestr As Integer
Dim secondstr As Integer
hourstr = timeleft \ 3600
minutestr = (timeleft - hourstr * 3600) \ 60
secondstr = timeleft - hourstr * 3600 - minutestr * 60
Label1.Caption = Format(hourstr, "00") & ":" & Format(minutestr, "00") & ":" & Format(secondstr, "00")
HScroll1.Max = countdown
HScroll1.Min = 0
HScroll1.Value = countdown - timeleft
End Sub
Private Sub Timer1_Timer()
Dim endtime As Date
If timeleft > 0 Then
If NowTime <> Now Then
NowTime = Now
endtime = DateAdd("s", countdown, StartTime)
timeleft = DateDiff("s", NowTime, endtime)
Call ShowTime
End If
Else
timeleft = countdown
Timer1.Interval = 0
End If
End Sub
上述代码粘贴到记事本,另存为Form1.frm,完全符合你的要求!
Begin VB.Form Form1
BorderStyle = 1 'Fixed Single
Caption = "Form1"
ClientHeight = 2400
ClientLeft = 45
ClientTop = 375
ClientWidth = 4635
LinkTopic = "Form1"
MaxButton = 0 'False
ScaleHeight = 2400
ScaleWidth = 4635
StartUpPosition = 3 '窗口缺省
Begin VB.Timer Timer1
Left = 1320
Top = 1920
End
Begin VB.CommandButton Command3
Caption = "结束"
Height = 375
Left = 3375
TabIndex = 4
Top = 1800
Width = 855
End
Begin VB.CommandButton Command2
Caption = "开始"
Height = 375
Left = 1875
TabIndex = 3
Top = 1800
Width = 855
End
Begin VB.CommandButton Command1
Caption = "设置"
Height = 375
Left = 375
TabIndex = 2
Top = 1800
Width = 855
End
Begin VB.HScrollBar HScroll1
Height = 375
Left = 360
TabIndex = 1
Top = 1320
Width = 3975
End
Begin VB.Label Label1
BeginProperty Font
Name = "宋体"
Size = 48
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 975
Left = 360
TabIndex = 0
Top = 240
Width = 3855
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim countdown As Long
Dim timeleft As Long
Dim StartTime As Date
Dim NowTime As Date
Private Sub Command1_Click()
Dim countstr As String
Do
countstr = InputBox("请输入倒计时分钟数(1~1440)!")
Loop While Not IsNumeric(countstr) Or Val(countstr) < 0 Or Val(countstr) > 1440
countdown = Int(Val(countstr) * 60)
timeleft = countdown
Call ShowTime
End Sub
Private Sub Command2_Click()
Timer1.Interval = 500
StartTime = Now
NowTime = StartTime
Call ShowTime
Call Timer1_Timer
End Sub
Private Sub Command3_Click()
Unload Me
End Sub
Private Sub Form_Load()
countdown = 0
timeleft = 0
Call ShowTime
End Sub
Private Sub ShowTime()
Dim hourstr As Integer
Dim minutestr As Integer
Dim secondstr As Integer
hourstr = timeleft \ 3600
minutestr = (timeleft - hourstr * 3600) \ 60
secondstr = timeleft - hourstr * 3600 - minutestr * 60
Label1.Caption = Format(hourstr, "00") & ":" & Format(minutestr, "00") & ":" & Format(secondstr, "00")
HScroll1.Max = countdown
HScroll1.Min = 0
HScroll1.Value = countdown - timeleft
End Sub
Private Sub Timer1_Timer()
Dim endtime As Date
If timeleft > 0 Then
If NowTime <> Now Then
NowTime = Now
endtime = DateAdd("s", countdown, StartTime)
timeleft = DateDiff("s", NowTime, endtime)
Call ShowTime
End If
Else
timeleft = countdown
Timer1.Interval = 0
End If
End Sub
上述代码粘贴到记事本,另存为Form1.frm,完全符合你的要求!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询