Public start As BooleanPrivate Sub Command4_Click()
start=false
Timer1.Enabled = True
End SubPrivate Sub Timer1_Timer()
start = True
Timer1.Interval = 1000
Shape14.Height = 10
Do While start = True
If Shape14.Height > 2000 Or start = False Then
Exit Do
Timer1.Enable = Flase
Else
Shape14.Height = Shape14.Height + 10
End If
Loop
End Sub
我想用一个按钮控制一个Start=Ture 进入这个状态shape14的高度就增加10每秒 一旦高度过2000或者start信号=false就停止增加高度...程序哪里有问题了?
和 do/while
Timer1.Enable = Flase
改成:
Timer1.Enable = Flase
Exit Do既然都Exit Do了 后面的Timer1.Enable = Flase就不起作用了
start=false
Timer1.Interval=1000 '添加这句
Timer1.Enabled = True
End Sub然后Timer3中的这句就可以去掉
Timer1.Enabled = True
Timer1.Interval = 1000 '这个直接在窗体是设置就可以了
Shape14.Height = 100
End SubPrivate Sub Timer1_Timer()
If Shape14.Height < 2000 Then
Shape14.Height = Shape14.Height + 100
Shape14.Top = Shape14.Top - 100 '应该向上增长吧,你的是向下长......
Else
Timer1.Enabled = False
End If
End Sub
Public start As Boolean
Private Declare Function GetTickCount Lib "kernel32" () As LongPrivate Sub Command4_Click()
start = False
Timer1.Interval = 1000
Timer1.Enabled = True
Command1.Enabled = False
End SubPrivate Sub Timer1_Timer()
Dim lngBeginTickCount As Long
lngBeginTickCount = GetTickCount
lngTime = Timer()
Timer1.Enabled = False
start = True
Shape14.Height = 10
Do While start = True
If Shape14.Height > 2000 Or start = False Then
Exit Do
Timer1.Enabled = False
Else
Shape14.Height = Shape14.Height + 10
Do Until GetTickCount - lngBeginTickCount > 2 '2毫秒刷新一次
' DoEvents
Loop
lngBeginTickCount = GetTickCount
End If
Loop
End Sub
Private Declare Function GetTickCount Lib "kernel32" () As LongPrivate Sub Command4_Click()
start = FalseCall ShowShapeEnd Sub
Private Sub ShowShape()
Dim lngBeginTickCount As Long
lngBeginTickCount = GetTickCount
lngTime = Timer()
Timer1.Enabled = False
start = True
Shape14.Height = 10
Do While start = True
If Shape14.Height > 2000 Or start = False Then
Exit Do
Timer1.Enabled = False
Else
Shape14.Height = Shape14.Height + 10
Do Until GetTickCount - lngBeginTickCount > 2 '2毫秒刷新一次
' DoEvents
Loop
lngBeginTickCount = GetTickCount
End If
Loop
End Sub
Private Sub Command4_Click()
Call ShowShape
End Sub
Private Sub ShowShape()
Dim lngBeginTickCount As Long
lngBeginTickCount = GetTickCount
Shape14.Height = 10
Do While True
If Shape14.Height > 2000 Then
Exit Do
Else
Shape14.Height = Shape14.Height + 10
Do Until GetTickCount - lngBeginTickCount > 2 '2毫秒刷新一次
' DoEvents
Loop
lngBeginTickCount = GetTickCount
End If
Loop
End Sub
Private Sub Form_Load()
Timer1.Interval = 1000
Shape14.Height = 10
End SubPrivate Sub Command4_Click()
Timer1.Enabled = Not Timer1.Enabled
End SubPrivate Sub Timer1_Timer()
With Shape14
If .Height > 2000 Then
Timer1.Enabled = False
Else
.Height = .Height + 10
End If
End With
End Sub
Timer1.Enabled = True
Timer1.Interval = 1000
Shape14.Height = 10End Sub
Private Sub Timer1_Timer()
If Shape14.Height > 2000 Then
Timer1.Enable = Flase
Else
Shape14.Height = Shape14.Height + 10
End If
End Sub
Private Sub Command4_Click()
Timer1.Enabled = True
Timer1.Interval = 1000
Shape14.Height = 10
End SubPrivate Sub Timer1_Timer()
If Shape14.Height > 2000 Then
Timer1.Enable = Flase
Else
Shape14.Height = Shape14.Height + 10
End If
End Sub
,应该你那大体的错误就是这样
去掉这个