vb 倒计时 30分急求
答案:3 悬赏:50
解决时间 2021-02-22 11:57
- 提问者网友:献世佛
- 2021-02-21 18:48
vb 倒计时 30分急求
最佳答案
- 二级知识专家网友:梦中风几里
- 2021-02-21 19:20
Option Explicit
Dim hh As Byte, mm As Byte, ss As Integer, h As Byte
Private Sub Form_Load()
hh = 1: mm = 0: ss = 9
Timer1.Interval = 1000
End Sub
Private Sub Timer1_Timer()
On Error Resume Next
Dim s As String * 2, m As String * 2, h As String * 2
s = IIf(ss < 10, "0" & ss, "" & ss)
m = IIf(mm < 10, "0" & mm, "" & mm)
h = IIf(hh < 10, "0" & hh, "" & hh)
If hh >= 24 Then hh = 24: h = "00"
Label1.Caption = h & ":" & m & ":" & s
ss = ss - 1
If mm = 0 And hh > 0 And ss = -1 Then
hh = hh - 1: mm = 60
End If
If hh + mm + ss = -1 Then
Timer1.Enabled = False
MsgBox "时间到", vbInformation, "提示"
End If
If ss = -1 And mm > 0 Then
mm = mm - 1: ss = 59
End If
End Sub
Dim hh As Byte, mm As Byte, ss As Integer, h As Byte
Private Sub Form_Load()
hh = 1: mm = 0: ss = 9
Timer1.Interval = 1000
End Sub
Private Sub Timer1_Timer()
On Error Resume Next
Dim s As String * 2, m As String * 2, h As String * 2
s = IIf(ss < 10, "0" & ss, "" & ss)
m = IIf(mm < 10, "0" & mm, "" & mm)
h = IIf(hh < 10, "0" & hh, "" & hh)
If hh >= 24 Then hh = 24: h = "00"
Label1.Caption = h & ":" & m & ":" & s
ss = ss - 1
If mm = 0 And hh > 0 And ss = -1 Then
hh = hh - 1: mm = 60
End If
If hh + mm + ss = -1 Then
Timer1.Enabled = False
MsgBox "时间到", vbInformation, "提示"
End If
If ss = -1 And mm > 0 Then
mm = mm - 1: ss = 59
End If
End Sub
全部回答
- 1楼网友:舊物识亽
- 2021-02-21 21:55
建立2个文本 2个按钮 4个TIMER Enabled 全设置成False添加一个WINDOWS MEDIA PLYAER 控件
Dim s As Long
Private Sub Command1_Click()
m = Text1.Text
s = m * 60
Timer1.Enabled = True
Timer2.Enabled = True
Timer4.Enabled = True
End Sub
Private Sub Command2_Click()
Label1.Caption = ""
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
End Sub
Private Sub Timer1_Timer() ,倒计时用 intrtvar设置1000这样才能按秒倒计时
s = s - 1
Label1.Caption = s
End Sub
Private Sub Timer2_Timer() intrtvar设置500
If Label1.Caption = Text2.Text Then
Timer3.Enabled = True
Timer2.Enabled = False
End If
End Sub
Private Sub Timer3_Timer()intrtvar 按照报警间隔设置
WindowsMediaPlayer1.Controls.play
End Sub
Private Sub Timer4_Timer()
If Label1.Caption = "0" Then
Label1.Caption = ""
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
End If
End Sub
Dim s As Long
Private Sub Command1_Click()
m = Text1.Text
s = m * 60
Timer1.Enabled = True
Timer2.Enabled = True
Timer4.Enabled = True
End Sub
Private Sub Command2_Click()
Label1.Caption = ""
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
End Sub
Private Sub Timer1_Timer() ,倒计时用 intrtvar设置1000这样才能按秒倒计时
s = s - 1
Label1.Caption = s
End Sub
Private Sub Timer2_Timer() intrtvar设置500
If Label1.Caption = Text2.Text Then
Timer3.Enabled = True
Timer2.Enabled = False
End If
End Sub
Private Sub Timer3_Timer()intrtvar 按照报警间隔设置
WindowsMediaPlayer1.Controls.play
End Sub
Private Sub Timer4_Timer()
If Label1.Caption = "0" Then
Label1.Caption = ""
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
End If
End Sub
- 2楼网友:往事隔山水
- 2021-02-21 20:59
Private Declare Function sndPlaySound Lib "Winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
'用API函数播放wav格式声音
'Option Explicit
Dim Hour_Int As Integer
Dim Minute_Int As Integer
Dim Second_Int As Integer
Dim S_Str As String
Dim M_Str As String
Dim H_Str As String
Dim Time_Str As String
Private Sub ply()
' SoundFile = "C:\windows\Media\The Microsoft Sound.WAV"
SoundFile = "e:\声音\闹钟响铃.WAV"
Result = sndPlaySound(SoundFile, 1)
End Sub
'开始倒计时
Private Sub Command1_Click()
Text1.Enabled = False
Label2.Enabled = False
Timer1.Enabled = True
Command2.Enabled = True
End Sub
'暂停倒计时
Private Sub Command2_Click()
Timer1.Enabled = Not Timer1.Enabled
Select Case Timer1.Enabled
Case True
Command2.Caption = "暂停"
Case False
Command2.Caption = "继续"
End Select
End Sub
'退出
Private Sub Command3_Click()
End
End Sub
Sub Form_click()
Timer1.Interval = 1000
Timer1.Enabled = False
Command2.Enabled = False
Hour_Int = InputBox("请输入倒计时的小时数:")
Minute_Int = InputBox("请输入倒计时的分时数:")
Second_Int = InputBox("请输入倒计时的秒数:")
H_Str = Val(Hour_Int)
M_Str = Val(Minute_Int)
S_Str = Val(Second_Int)
Time_Str = H_Str & ":" & M_Str & ":" & S_Str
Label1.Caption = Time_Str
Text1.Visible = False
End Sub
'倒计时
Sub Timer1_Timer()
'显示剩余时间
S_Str = IIf(Second_Int < 10, "0" & Second_Int, "" & Second_Int)
M_Str = IIf(Minute_Int < 10, "0" & Minute_Int, "" & Minute_Int)
H_Str = IIf(Hour_Int < 10, "0" & Hour_Int, "" & Hour_Int)
Time_Str = H_Str & ":" & M_Str & ":" & S_Str
Label1.Caption = Time_Str
Second_Int = Second_Int - 1
If Hour_Int = 0 And Minute_Int = 0 And Second_Int = -1 Then
Call ply
MsgBox "时间到!!!"
Timer1.Enabled = False
End If
If Second_Int = -1 And Minute_Int > 0 Then
Minute_Int = Minute_Int - 1
Second_Int = 59
End If
If Minute_Int = 0 And Hour_Int > 0 Then
Hour_Int = Hour_Int - 1
Minute_Int = 59
End If
End Sub
'用API函数播放wav格式声音
'Option Explicit
Dim Hour_Int As Integer
Dim Minute_Int As Integer
Dim Second_Int As Integer
Dim S_Str As String
Dim M_Str As String
Dim H_Str As String
Dim Time_Str As String
Private Sub ply()
' SoundFile = "C:\windows\Media\The Microsoft Sound.WAV"
SoundFile = "e:\声音\闹钟响铃.WAV"
Result = sndPlaySound(SoundFile, 1)
End Sub
'开始倒计时
Private Sub Command1_Click()
Text1.Enabled = False
Label2.Enabled = False
Timer1.Enabled = True
Command2.Enabled = True
End Sub
'暂停倒计时
Private Sub Command2_Click()
Timer1.Enabled = Not Timer1.Enabled
Select Case Timer1.Enabled
Case True
Command2.Caption = "暂停"
Case False
Command2.Caption = "继续"
End Select
End Sub
'退出
Private Sub Command3_Click()
End
End Sub
Sub Form_click()
Timer1.Interval = 1000
Timer1.Enabled = False
Command2.Enabled = False
Hour_Int = InputBox("请输入倒计时的小时数:")
Minute_Int = InputBox("请输入倒计时的分时数:")
Second_Int = InputBox("请输入倒计时的秒数:")
H_Str = Val(Hour_Int)
M_Str = Val(Minute_Int)
S_Str = Val(Second_Int)
Time_Str = H_Str & ":" & M_Str & ":" & S_Str
Label1.Caption = Time_Str
Text1.Visible = False
End Sub
'倒计时
Sub Timer1_Timer()
'显示剩余时间
S_Str = IIf(Second_Int < 10, "0" & Second_Int, "" & Second_Int)
M_Str = IIf(Minute_Int < 10, "0" & Minute_Int, "" & Minute_Int)
H_Str = IIf(Hour_Int < 10, "0" & Hour_Int, "" & Hour_Int)
Time_Str = H_Str & ":" & M_Str & ":" & S_Str
Label1.Caption = Time_Str
Second_Int = Second_Int - 1
If Hour_Int = 0 And Minute_Int = 0 And Second_Int = -1 Then
Call ply
MsgBox "时间到!!!"
Timer1.Enabled = False
End If
If Second_Int = -1 And Minute_Int > 0 Then
Minute_Int = Minute_Int - 1
Second_Int = 59
End If
If Minute_Int = 0 And Hour_Int > 0 Then
Hour_Int = Hour_Int - 1
Minute_Int = 59
End If
End Sub
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯