用VB编写了一个秒表程序,有两个问题不明白,请高手指点一下,谢谢。
秒表刚开始运行时,最前面就显示“12”,1秒以后才变为“01”。并且前面还有“上午”两个字符。请问:如何去掉“上午”两个字?并且一开始不要显示“12”而是“00”。———...
秒表刚开始运行时,最前面就显示“12”,1秒以后才变为“01”。并且前面还有
“上午”两个字符。
请问:如何去掉“上午”两个字?并且一开始不要显示“12
”而是“00”。
——————————————————————
源程序如下:
Dim flag As Boolean
Dim mytime, ttime, mydate, yourdate, yourtime As Date
Private Sub cmdStart_Click()Timer1.Interval = 1
If cmdStart.Caption = "开始" Then cmdStart.Caption = "停止" cmdCls.Enabled = FalseElse cmdStart.Caption = "开始" cmdCls.Enabled = TrueEnd If
End Sub
Private Sub cmdCls_Click()ttime = "00:00:00"lblShowTime.Caption = CStr(ttime)End Sub
Private Sub cmdTime_Click()
If cmdTime.Caption = "时间" ThencmdTime.Caption = "秒表"Timer1.Interval = 1000ttime = "00:00:00"cmdStart.Enabled = FalsecmdCls.Enabled = FalseElsecmdTime.Caption = "时间"cmdStart.Enabled = Truettime = "00:00:00"lblShowTime.Caption = CStr(ttime)End If
End Sub
Private Sub cmdAlarm_Click()Me.Height = 2850Me.Frame2.Visible = True
End Sub
Private Sub cmdDate_Click()Me.lblShowDate.Caption = CStr(mydate)
End Sub
Private Sub cmdClose_Click()Unload frmClock
End Sub
Private Sub cmdOK_Click()
Me.Frame2.Visible = FalseMe.Height = 1695yourdate = CDate(rtbdate.Text)yourtime = CDate(rtbtime.Text)'Me.rtbdate.Text = rtbtime.Textrtbdate.SaveFile ("c:\date.txt")'Me.rtbtime.Text = rtbdate.Textrtbtime.SaveFile ("c:\time.txt")End Sub
Private Sub Form_Load() On Error Resume Next Me.Height = 1620rtbdate.LoadFile ("c:\date.txt")yourdate = CDate(rtbdate.Text)'rtbtime.Text = CStr(yourtime)rtbtime.LoadFile "c:\time.txt"yourtime = CDate(rtbtime.Text)'rtbdate.Text = CStr(yourtime)Me.ShowEnd Sub
Private Sub Label4_Click()
End Sub
Private Sub Timer1_Timer()mydate = Datemytime = TimeIf cmdTime.Caption = "秒表" Then lblShowTime.Caption = CStr(mytime)ElseIf (cmdTime.Caption = "时间" And cmdStart.Caption = "停止") Then lblShowTime.Caption = CStr(ttime) ttime = TimeValue(ttime) + TimeValue("00:00:01")End IfIf ((chkAlarm.Value = 0) And Hour(mytime) = Hour(yourtime) And Minute(mytime) = Minute(yourtime) And (mydate = yourdate)) Then
Beep
End If
End Sub 展开
“上午”两个字符。
请问:如何去掉“上午”两个字?并且一开始不要显示“12
”而是“00”。
——————————————————————
源程序如下:
Dim flag As Boolean
Dim mytime, ttime, mydate, yourdate, yourtime As Date
Private Sub cmdStart_Click()Timer1.Interval = 1
If cmdStart.Caption = "开始" Then cmdStart.Caption = "停止" cmdCls.Enabled = FalseElse cmdStart.Caption = "开始" cmdCls.Enabled = TrueEnd If
End Sub
Private Sub cmdCls_Click()ttime = "00:00:00"lblShowTime.Caption = CStr(ttime)End Sub
Private Sub cmdTime_Click()
If cmdTime.Caption = "时间" ThencmdTime.Caption = "秒表"Timer1.Interval = 1000ttime = "00:00:00"cmdStart.Enabled = FalsecmdCls.Enabled = FalseElsecmdTime.Caption = "时间"cmdStart.Enabled = Truettime = "00:00:00"lblShowTime.Caption = CStr(ttime)End If
End Sub
Private Sub cmdAlarm_Click()Me.Height = 2850Me.Frame2.Visible = True
End Sub
Private Sub cmdDate_Click()Me.lblShowDate.Caption = CStr(mydate)
End Sub
Private Sub cmdClose_Click()Unload frmClock
End Sub
Private Sub cmdOK_Click()
Me.Frame2.Visible = FalseMe.Height = 1695yourdate = CDate(rtbdate.Text)yourtime = CDate(rtbtime.Text)'Me.rtbdate.Text = rtbtime.Textrtbdate.SaveFile ("c:\date.txt")'Me.rtbtime.Text = rtbdate.Textrtbtime.SaveFile ("c:\time.txt")End Sub
Private Sub Form_Load() On Error Resume Next Me.Height = 1620rtbdate.LoadFile ("c:\date.txt")yourdate = CDate(rtbdate.Text)'rtbtime.Text = CStr(yourtime)rtbtime.LoadFile "c:\time.txt"yourtime = CDate(rtbtime.Text)'rtbdate.Text = CStr(yourtime)Me.ShowEnd Sub
Private Sub Label4_Click()
End Sub
Private Sub Timer1_Timer()mydate = Datemytime = TimeIf cmdTime.Caption = "秒表" Then lblShowTime.Caption = CStr(mytime)ElseIf (cmdTime.Caption = "时间" And cmdStart.Caption = "停止") Then lblShowTime.Caption = CStr(ttime) ttime = TimeValue(ttime) + TimeValue("00:00:01")End IfIf ((chkAlarm.Value = 0) And Hour(mytime) = Hour(yourtime) And Minute(mytime) = Minute(yourtime) And (mydate = yourdate)) Then
Beep
End If
End Sub 展开
5个回答
展开全部
你的代码是1秒后才正常显示 这个你可以 再启用 timer 控件时 直接 调用一下它的 timer 事件,就可以解决
不让显示 上午 这个你可以用 Format 格式化一下你的日期 就行了
eg: label1.caption=Format(now,"hh:mm:ss")
还有你的语法问题
VB 内不能 这样申请变量
'Dim mytime, ttime, mydate, yourdate, yourtime As Date
到最后 你只有一个 是 date 类型的 一个一个的来
dim mytime as date,ttime as date,mydate as date,yourdate as date,yourtime as date
不让显示 上午 这个你可以用 Format 格式化一下你的日期 就行了
eg: label1.caption=Format(now,"hh:mm:ss")
还有你的语法问题
VB 内不能 这样申请变量
'Dim mytime, ttime, mydate, yourdate, yourtime As Date
到最后 你只有一个 是 date 类型的 一个一个的来
dim mytime as date,ttime as date,mydate as date,yourdate as date,yourtime as date
追问
谢谢回答 ,麻烦给修改一下代码,调试一下好吗?
追答
Private Sub cmdStart_Click()
Timer1.Interval = 1
If cmdStart.Caption = "开始" Then
cmdStart.Caption = "停止"
cmdCls.Enabled = False
Else
cmdStart.Caption = "开始"
cmdCls.Enabled = True
Timer1_Timer'这里加了一句
End If
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub cmdTime_Click()
If cmdTime.Caption = "时间" Then
cmdTime.Caption = "秒表"
Timer1.Interval = 1000
ttime = "00:00:00"
cmdStart.Enabled = False
cmdCls.Enabled = False
Else
cmdTime.Caption = "时间"
cmdStart.Enabled = True
ttime = CDate("00:00:00")'''这里
lblShowTime.Caption = Format(ttime, "hh:mm:ss") ' CStr(ttime)'这里也改了一下
End If
End Sub
''''''''''''''''''''''''''''''''''''''''
Private Sub Timer1_Timer()
mydate = Date
mytime = Time
If cmdTime.Caption = "秒表" Then
lblShowTime.Caption = Format(mytime, "hh:mm:ss") ' CStr(mytime) <==
ElseIf (cmdTime.Caption = "时间" And cmdStart.Caption = "停止") Then
lblShowTime.Caption = Format(ttime, "hh:mm:ss") ' CStr(ttime)' <==
'ttime = TimeValue(ttime) + TimeValue("00:00:01")
ttime = DateAdd("s", 1, ttime)'和你的差不多
End If
If ((chkAlarm.Value = 0) And Hour(mytime) = Hour(yourtime) And Minute(mytime) = Minute(yourtime) And (mydate = yourdate)) Then
Beep
End If
End Sub
展开全部
Private Sub Timer1_Timer()
mydate = Date
mytime = Time ***************把这一句去掉
If cmdTime.Caption = "秒表" Then
lblShowTime.Caption = CStr(mytime)
ElseIf (cmdTime.Caption = "时间" And cmdStart.Caption = "停止") Then
lblShowTime.Caption = CStr(ttime)
ttime = TimeValue(ttime) + TimeValue("00:00:01")
End If
If ((chkAlarm.Value = 0) And Hour(mytime) = Hour(yourtime) And Minute(mytime) = Minute(yourtime) And (mydate = yourdate)) Then
Beep
End If
End Sub
mydate = Date
mytime = Time ***************把这一句去掉
If cmdTime.Caption = "秒表" Then
lblShowTime.Caption = CStr(mytime)
ElseIf (cmdTime.Caption = "时间" And cmdStart.Caption = "停止") Then
lblShowTime.Caption = CStr(ttime)
ttime = TimeValue(ttime) + TimeValue("00:00:01")
End If
If ((chkAlarm.Value = 0) And Hour(mytime) = Hour(yourtime) And Minute(mytime) = Minute(yourtime) And (mydate = yourdate)) Then
Beep
End If
End Sub
追问
谢谢回答 ,麻烦给修改一下代码,调试一下好吗?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
把所有的lblShowTime.Caption = CStr(ttime)改成
lblShowTime.Caption = format(ttime,"hh:mm:ss")就可以了,VB缺省用12小时制,所以00:00:01是上午12点过1秒,12小时制是没有0点的,只有1点~12点
lblShowTime.Caption = format(ttime,"hh:mm:ss")就可以了,VB缺省用12小时制,所以00:00:01是上午12点过1秒,12小时制是没有0点的,只有1点~12点
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
HI我,我帮你改好了传你
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
源代码发到278700294@qq.com,改好了传给你
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询