一个关于VB的计数器程序

来源:百度知道 编辑:UC知道 时间:2024/06/30 13:17:34
要求设计一个计数器。
在一个文本框中输入一个正整数。开始后
1、每秒此数减1,直到0为止。再每秒加1,到这个数为止。反复进行。
2、从0开始每秒加1,直到此数。再每秒减1,直到0,反复进行。
开始后,
1和2是二个程序,回答其中一个即可。

Private Sub Form_Load()

Text1.Text = "10"
Text2.Text = "0"
Timer1.Interval = 1000
Timer1.Enabled = True
a = Text1.Text
End Sub

Private Sub Timer1_Timer()
Text1.Text = Text1.Text - 1

Text2.Text = Text2.Text + 1
If Text1.Text = 0 And Text2.Text = a Then
Timer1.Enabled = False
End If
End Sub

Option Explicit

Dim X As Integer

Private Sub Command1_Click()
X = CInt(Text1.Text)
Me.Timer1.Interval = 1000
Me.Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()

If CInt(Text1.Text) > 0 Then
Text1.Text = CInt(Text1.Text) - 1
ElseIf CInt(Text1.Text) < X Then
Text1.Text = CInt(Text1.Text) + 1
End If

End Sub

先定义两个窗体层变量S,B
Private Sub Form_Load()
S = Text1.Text
B = 1
end sub
再编写Timer事件:
Private Sub Timer1_Timer()
If Text1.Text = "0"