vb的倒计时
对于倒计时一直比较郁闷,因为各种语言都有自己固定的定时器,vb学过那么几天后来在各种语言之间转来转去的,再加上大学之后这么语言就变得不太实用了,让后就默默的抛弃了这门语言,说点儿实在的,其实vb语法简单易懂,学起来相当容易,不知道为什么就成了现在这样,为了纪念我学的第一门后端语言,所有第一篇博客就选择vb了。
代码如下
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 6945
ClientLeft = 120
ClientTop = 450
ClientWidth = 10620
LinkTopic = "Form1"
ScaleHeight = 6945
ScaleWidth = 10620
StartUpPosition = 3 '窗口缺省
Begin VB.Timer Timer1
Left = 4560
Top = 2760
End
Begin VB.TextBox Text1
Height = 495
Left = 1080
TabIndex = 1
Text = "Text1"
Top = 1440
Width = 2775
End
Begin VB.CommandButton Command1
Caption = "开始"
Height = 615
Left = 1200
TabIndex = 0
Top = 2640
Width = 2535
End
Begin VB.Label Label1
Caption = "请输入倒计时分钟数"
Height = 375
Left = 1080
TabIndex = 2
Top = 600
Width = 2655
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim sec As Long
Dim min As Long
Private Sub Command1_Click()
min = Text1.Text
If min = 0 Then
Text1.Text = 请输入分钟
End If
If min > 0 Then
Timer1.Enabled = True
Timer1.Interval = 1000
sec = min * 60
Command1.Visible = False
End If
Command1.Visible = False
Label1.Caption = "开始倒计时"
End Sub
Private Sub Timer1_Timer()
Dim a
sec = sec - 1
Text1.Text = sec
If sec = 0 Then
a = MsgBox("时间到", 0)
If a = 1 Then
Text1.Text = 0
Command1.Visible = True
Timer1.Enabled = False
End If
End If
End Sub