VB计时器的编辑
合集下载
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
s = Val(Right(strNow1, 2))
m = Val(Mid(strNow1, 4, 3))
s = s + h * 3600 + m * 60 '今天已经过去的秒数
nSec = 86400 - s + tSec '目标当天到截止点的秒数与今天已过去的秒数之和
If nSec > 86400 Then
3)程序中调用系统时间使用了“Now”函数,可以按照“小时:分钟:秒”的形式返回当前时间。
4)为保证应用程序的灵活性,应在倒计时牌上设有暂停、继续、时间校正、时区切换,结束运行等特殊要求的激发点。
5)按照需要构筑程序框架并编写应用程序。
六、调试过程及实验结果
实验界面:
七、附录(源程序清单)
Dim a As Long, b As Long, c As Long, mmonth As Integer
毅字楼404西北工业大学20102011学年第一学期软件技术实验报告七附录源程序清单dimaaslongbaslongcaslongmmonthasintegerdimnyearasintegerndayasintegernmonthasintegermdayasinteger本年的年月日变量以及目标年不足一年的天数与当前年剩余天数之和dimtyearasintegertdayasintegeroyearasintegertmonthasinteger目标年的年天数本年与目标年之差dimnsecaslongtsecaslong今天已经过去的秒数目标天0点距离截止点的秒数其中nsec最终为倒计时不足一天的剩余秒数dimstrnow1asstringstrnow2asstringzhutiasstring取今天年月日和今天时分秒的字符串变量dimstrend1asstringstrend2asstring取目标截止时的年月日时分秒的字符串变量dimhaslongmaslongsaslong时分秒计数变量dimodayasintegerpdayasintegerxdayasintegerzdayasinteger今天和目标天秒数之和大于1天的临时变量值和今年中本月以前的天数累加和计数变量判月函数本月最大值取值dimiasintegerkasintegerflagasinteger循环控制变量以及闰年处理中二月天数处理变量privatesubcheck1clicktext1text南非世界杯
Select Case Combo1.Text
Case "中国北京"
h = Val(Left(strNow1, 2))
Case "英国伦敦"
h = Val(Left(strNow1, 2)) - 8
Case "美国纽约"
h = Val(Left(strNow1, 2)) - 13
End Select
Timer1.Enabled = False
Label2.Caption = "0"
Label4.Caption = "000"
Label6.Caption = "000000"
Label12.Caption = "00"
Label14.Caption = "00"
End Sub
Private Sub Command5_Click()
If nYear Mod 4 = 0 And nYear Mod 100 <> 0 Or nYear Mod 400 = 0 Then
k = 1
Else
k = 0
End If
Select Case nmonth
Case 1, 3, 5, 7, 8, 10, 12
xday = 31
Case 2
xday = 28 &oday = 1 '今天还剩余的秒数与目标天从零点到目标时间点的秒数之和大于86400(1天)时的处理
Else
oday = 0
End If
a = nSec / 3600 - 1
b = (nSec - a * 3600) / 60
c = nSec - a * 3600 - b * 60
5、用Dim对数值类型的定义
五、算法描述及实验步骤
1)根据实验设计需要在窗体上放上若干所需的标签控件、文本框控件、时钟控件、框架控件、组合框控件、命令按钮控件等,并设置各控件的必要属性值;
2)在程序中用时钟控件不断触发系统时间与预设定时间时间截止点的时间差:分别计算当前时间和预设定时间截止点之间相差的整年数、当前时间到时间截止点还差的不足一年的天数和当前时间到时间截止点之间相差的不足一天的秒数并分别显示之。
Dim nYear As Integer, nDay As Integer, nmonth As Integer, mday As Integer '本年的年、月、日变量以及目标年不足一年的天数与当前年剩余天数之和
Dim tYear As Integer, tDay As Integer, oyear As Integer, tmonth As Integer '目标年的年、天数、本年与目标年之差
Dim t1 As Long, t2 As Long, t3 As Long, t As String
t1 = Timer
t = InputBox("请输入校正时间的秒数值!", "校正时间")
If t = "" Then
Form1.Show
Else
t2 = Timer
t3 = t2 - t1
nSec = nSec + Int(t) + t3
tYear = Val(Right(strEnd1, 4))
tmonth = Val(Left(strEnd1, 2)) - 1
pday = 0
For i = 1 To tmonth '累计目标年从1月1日到目标日的天数
panyue i, tYear
pday = pday + zday
Next i
tDay = pday + Val(Mid(strEnd1, 4, 2)) - 1
pday = 366 - pday + oday
mday = (pday + tDay) Mod 366
Else
pday = 365 - pday + oday
mday = (pday + tDay) Mod 365 '判断本年是否闰年,并做相应的天数处理
End If
If tYear - nYear > 0 Then
s = 0
m = 0
h = 0
nDay = 1
nmonth = nmonth + 1
ElseIf s = 59 And m = 59 And h = 23 And nDay = xday And nmonth = 12 And nYear < 9999 Then
Dim i As Integer, k As Integer, flag As Integer '循环控制变量以及闰年处理中二月天数处理变量
Private Sub Check1_Click()
Text1.Text = "南非世界杯!"
End Sub
Private Sub Command1_Click()
tSec = Val(Left(strEnd2, 2)) * 3600 + Val(Mid(strEnd2, 4, 2)) * 60 + Val(Right(strEnd2, 2))
Label1.Caption = "距离" + Right(strEnd1, 4) + "年" + Left(strEnd1, 2) + "月" + Mid(strEnd1, 4, 2) + "日" + strzhuti + "还有:"
软件技术实验报告
班级
学号
姓名
实验
名称
计时器的编辑
实验
序号
实验
成绩
一、实验名称
计时器的编辑
二、实验目的及要求
运用VB中提供的界面生成一个计时器,可以进行计时的功能
三、实验环境
Visual Bisic 6.0
四、实验内容
1、学习使用按键数组
2、练习使用if语句
3、使用计时器
4、;练习使用inputbox
panyue i, nYear
pday = pday + zday 'pday是累加天数结果,zday是panyue函数返回结果
Next i
pday = pday + nDay '本年已经过去的整月天数加上本月已经过去的天数
If nYear Mod 4 = 0 And nYear Mod 100 <> 0 Or nYear Mod 400 = 0 Then
k = 1
Else
k = 0
End If
Select Case xmonth
Case 1, 3, 5, 7, 8, 10, 12
zday = 31
Case 2
zday = 28 + k
Case 4, 6, 9, 11
zday = 30
End Select
End Sub
Sub showtime1()
'以下是独立时钟当前年当前月的最大取值设定
strNow1 = Format(Now, "hh:mm:ss") '今天的时分秒
strNow2 = Format(Now, "yyyy-mm-dd") '今天的年月日
nYear = Val(Left(strNow2, 4)) - 1
nmonth = Val(Mid(strNow2, 6, 2))
nDay = Val(Right(strNow2, 2)) '今天之前本月已经过去的天数
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
showtime1
Label19.Caption = Now
End Sub
Sub panyue(xmonth As Integer, xyear As Integer)
If xyear Mod 4 = 0 And xyear Mod 100 <> 0 Or xyear Mod 400 = 0 Then
strzhuti = InputBox$("请输入活动主题:", "", "南非世界杯")
strEnd1 = InputBox$("请输入倒计时截止日期:(格式:月-日-年)", "", "06-03-2010")
strEnd2 = InputBox$("请输入倒计时截止时间:(格式:时:分:秒)", "", "20:00:00")
s = 0
m = 0
h = h + 1
ElseIf s = 59 And m = 59 And h = 23 And nDay < xday Then
s = 0
m = 0
h = 0
nDay = nDay + 1
ElseIf s = 59 And m = 59 And h = 23 And nDay = xday And nmonth < 12 Then
oyear = tYear - nYear - 1 + (tDay + oday) \ 365
Else
oyear = 0
End If
mmonth = mday / 30 - 1
mday = mday - mmonth * 30
If (mday > 30) Then
mmonth = mmonth + 1
mday = mday - 30
End If
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
flag = 1
End Sub
Private Sub Command3_Click()
flag = 0
End Sub
Private Sub Command4_Click()
Case 4, 6, 9, 11
xday = 30
End Select
'以下是独立时钟当前年月日、时分秒的进位处理
If s < 59 Then
s = s + 1
ElseIf s = 59 And m < 59 Then
s = 0
m = m + 1
ElseIf s = 59 And m = 59 And h < 23 Then
Dim nSec As Long, tSec As Long '今天已经过去的秒数、目标天0点距离截止点的秒数(其中nSec最终为倒计时不足一天的剩余秒数
Dim strNow1 As String, strNow2 As String, zhuti As String '取今天年月日和今天时分秒的字符串变量
Dim strEnd1 As String, strEnd2 As String '取目标截止时的年月日、时分秒的字符串变量
Dim h As Long, m As Long, s As Long '时分秒计数变量
Dim oday As Integer, pday As Integer, xday As Integer, zday As Integer '今天和目标天秒数之和大于1天的临时变量值和今年中本月以前的天数累加和计数变量,判月函数本月最大值取值
End If
End Sub
Private Sub Command7_Click()
If MsgBox("您确认要离开吗?", vbYesNo + vbDefaultButton1 + vbInformation, "离开确认") = vbYes Then
Unload Me
End If
End Sub
Private Sub Form_Load()
If (c < 0) Then
c = c + 60
b = b - 1
End If
If (c > 60) Then
c = c - 60
b = b + 1
End If
If (b > 60) Then
b = b - 60
a = a + 1
End If
pday = 0
For i = 1 To nmonth - 1 '累计本年已经过去的天数
nYear = 0: mday = 0: tYear = 0: tDay = 0: oyear = 0
nSec = 0: tSec = 0: tmonth = 0
i = 0: pday = 0
m = Val(Mid(strNow1, 4, 3))
s = s + h * 3600 + m * 60 '今天已经过去的秒数
nSec = 86400 - s + tSec '目标当天到截止点的秒数与今天已过去的秒数之和
If nSec > 86400 Then
3)程序中调用系统时间使用了“Now”函数,可以按照“小时:分钟:秒”的形式返回当前时间。
4)为保证应用程序的灵活性,应在倒计时牌上设有暂停、继续、时间校正、时区切换,结束运行等特殊要求的激发点。
5)按照需要构筑程序框架并编写应用程序。
六、调试过程及实验结果
实验界面:
七、附录(源程序清单)
Dim a As Long, b As Long, c As Long, mmonth As Integer
毅字楼404西北工业大学20102011学年第一学期软件技术实验报告七附录源程序清单dimaaslongbaslongcaslongmmonthasintegerdimnyearasintegerndayasintegernmonthasintegermdayasinteger本年的年月日变量以及目标年不足一年的天数与当前年剩余天数之和dimtyearasintegertdayasintegeroyearasintegertmonthasinteger目标年的年天数本年与目标年之差dimnsecaslongtsecaslong今天已经过去的秒数目标天0点距离截止点的秒数其中nsec最终为倒计时不足一天的剩余秒数dimstrnow1asstringstrnow2asstringzhutiasstring取今天年月日和今天时分秒的字符串变量dimstrend1asstringstrend2asstring取目标截止时的年月日时分秒的字符串变量dimhaslongmaslongsaslong时分秒计数变量dimodayasintegerpdayasintegerxdayasintegerzdayasinteger今天和目标天秒数之和大于1天的临时变量值和今年中本月以前的天数累加和计数变量判月函数本月最大值取值dimiasintegerkasintegerflagasinteger循环控制变量以及闰年处理中二月天数处理变量privatesubcheck1clicktext1text南非世界杯
Select Case Combo1.Text
Case "中国北京"
h = Val(Left(strNow1, 2))
Case "英国伦敦"
h = Val(Left(strNow1, 2)) - 8
Case "美国纽约"
h = Val(Left(strNow1, 2)) - 13
End Select
Timer1.Enabled = False
Label2.Caption = "0"
Label4.Caption = "000"
Label6.Caption = "000000"
Label12.Caption = "00"
Label14.Caption = "00"
End Sub
Private Sub Command5_Click()
If nYear Mod 4 = 0 And nYear Mod 100 <> 0 Or nYear Mod 400 = 0 Then
k = 1
Else
k = 0
End If
Select Case nmonth
Case 1, 3, 5, 7, 8, 10, 12
xday = 31
Case 2
xday = 28 &oday = 1 '今天还剩余的秒数与目标天从零点到目标时间点的秒数之和大于86400(1天)时的处理
Else
oday = 0
End If
a = nSec / 3600 - 1
b = (nSec - a * 3600) / 60
c = nSec - a * 3600 - b * 60
5、用Dim对数值类型的定义
五、算法描述及实验步骤
1)根据实验设计需要在窗体上放上若干所需的标签控件、文本框控件、时钟控件、框架控件、组合框控件、命令按钮控件等,并设置各控件的必要属性值;
2)在程序中用时钟控件不断触发系统时间与预设定时间时间截止点的时间差:分别计算当前时间和预设定时间截止点之间相差的整年数、当前时间到时间截止点还差的不足一年的天数和当前时间到时间截止点之间相差的不足一天的秒数并分别显示之。
Dim nYear As Integer, nDay As Integer, nmonth As Integer, mday As Integer '本年的年、月、日变量以及目标年不足一年的天数与当前年剩余天数之和
Dim tYear As Integer, tDay As Integer, oyear As Integer, tmonth As Integer '目标年的年、天数、本年与目标年之差
Dim t1 As Long, t2 As Long, t3 As Long, t As String
t1 = Timer
t = InputBox("请输入校正时间的秒数值!", "校正时间")
If t = "" Then
Form1.Show
Else
t2 = Timer
t3 = t2 - t1
nSec = nSec + Int(t) + t3
tYear = Val(Right(strEnd1, 4))
tmonth = Val(Left(strEnd1, 2)) - 1
pday = 0
For i = 1 To tmonth '累计目标年从1月1日到目标日的天数
panyue i, tYear
pday = pday + zday
Next i
tDay = pday + Val(Mid(strEnd1, 4, 2)) - 1
pday = 366 - pday + oday
mday = (pday + tDay) Mod 366
Else
pday = 365 - pday + oday
mday = (pday + tDay) Mod 365 '判断本年是否闰年,并做相应的天数处理
End If
If tYear - nYear > 0 Then
s = 0
m = 0
h = 0
nDay = 1
nmonth = nmonth + 1
ElseIf s = 59 And m = 59 And h = 23 And nDay = xday And nmonth = 12 And nYear < 9999 Then
Dim i As Integer, k As Integer, flag As Integer '循环控制变量以及闰年处理中二月天数处理变量
Private Sub Check1_Click()
Text1.Text = "南非世界杯!"
End Sub
Private Sub Command1_Click()
tSec = Val(Left(strEnd2, 2)) * 3600 + Val(Mid(strEnd2, 4, 2)) * 60 + Val(Right(strEnd2, 2))
Label1.Caption = "距离" + Right(strEnd1, 4) + "年" + Left(strEnd1, 2) + "月" + Mid(strEnd1, 4, 2) + "日" + strzhuti + "还有:"
软件技术实验报告
班级
学号
姓名
实验
名称
计时器的编辑
实验
序号
实验
成绩
一、实验名称
计时器的编辑
二、实验目的及要求
运用VB中提供的界面生成一个计时器,可以进行计时的功能
三、实验环境
Visual Bisic 6.0
四、实验内容
1、学习使用按键数组
2、练习使用if语句
3、使用计时器
4、;练习使用inputbox
panyue i, nYear
pday = pday + zday 'pday是累加天数结果,zday是panyue函数返回结果
Next i
pday = pday + nDay '本年已经过去的整月天数加上本月已经过去的天数
If nYear Mod 4 = 0 And nYear Mod 100 <> 0 Or nYear Mod 400 = 0 Then
k = 1
Else
k = 0
End If
Select Case xmonth
Case 1, 3, 5, 7, 8, 10, 12
zday = 31
Case 2
zday = 28 + k
Case 4, 6, 9, 11
zday = 30
End Select
End Sub
Sub showtime1()
'以下是独立时钟当前年当前月的最大取值设定
strNow1 = Format(Now, "hh:mm:ss") '今天的时分秒
strNow2 = Format(Now, "yyyy-mm-dd") '今天的年月日
nYear = Val(Left(strNow2, 4)) - 1
nmonth = Val(Mid(strNow2, 6, 2))
nDay = Val(Right(strNow2, 2)) '今天之前本月已经过去的天数
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
showtime1
Label19.Caption = Now
End Sub
Sub panyue(xmonth As Integer, xyear As Integer)
If xyear Mod 4 = 0 And xyear Mod 100 <> 0 Or xyear Mod 400 = 0 Then
strzhuti = InputBox$("请输入活动主题:", "", "南非世界杯")
strEnd1 = InputBox$("请输入倒计时截止日期:(格式:月-日-年)", "", "06-03-2010")
strEnd2 = InputBox$("请输入倒计时截止时间:(格式:时:分:秒)", "", "20:00:00")
s = 0
m = 0
h = h + 1
ElseIf s = 59 And m = 59 And h = 23 And nDay < xday Then
s = 0
m = 0
h = 0
nDay = nDay + 1
ElseIf s = 59 And m = 59 And h = 23 And nDay = xday And nmonth < 12 Then
oyear = tYear - nYear - 1 + (tDay + oday) \ 365
Else
oyear = 0
End If
mmonth = mday / 30 - 1
mday = mday - mmonth * 30
If (mday > 30) Then
mmonth = mmonth + 1
mday = mday - 30
End If
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
flag = 1
End Sub
Private Sub Command3_Click()
flag = 0
End Sub
Private Sub Command4_Click()
Case 4, 6, 9, 11
xday = 30
End Select
'以下是独立时钟当前年月日、时分秒的进位处理
If s < 59 Then
s = s + 1
ElseIf s = 59 And m < 59 Then
s = 0
m = m + 1
ElseIf s = 59 And m = 59 And h < 23 Then
Dim nSec As Long, tSec As Long '今天已经过去的秒数、目标天0点距离截止点的秒数(其中nSec最终为倒计时不足一天的剩余秒数
Dim strNow1 As String, strNow2 As String, zhuti As String '取今天年月日和今天时分秒的字符串变量
Dim strEnd1 As String, strEnd2 As String '取目标截止时的年月日、时分秒的字符串变量
Dim h As Long, m As Long, s As Long '时分秒计数变量
Dim oday As Integer, pday As Integer, xday As Integer, zday As Integer '今天和目标天秒数之和大于1天的临时变量值和今年中本月以前的天数累加和计数变量,判月函数本月最大值取值
End If
End Sub
Private Sub Command7_Click()
If MsgBox("您确认要离开吗?", vbYesNo + vbDefaultButton1 + vbInformation, "离开确认") = vbYes Then
Unload Me
End If
End Sub
Private Sub Form_Load()
If (c < 0) Then
c = c + 60
b = b - 1
End If
If (c > 60) Then
c = c - 60
b = b + 1
End If
If (b > 60) Then
b = b - 60
a = a + 1
End If
pday = 0
For i = 1 To nmonth - 1 '累计本年已经过去的天数
nYear = 0: mday = 0: tYear = 0: tDay = 0: oyear = 0
nSec = 0: tSec = 0: tmonth = 0
i = 0: pday = 0