关于vb中timer的延时怎么写代码?
想编个唐诗鉴赏的小程序,用timer怎么写代码,可以每隔5秒出现一句诗,点击command停止,再次点击则继续?...
想编个唐诗鉴赏的小程序,用timer怎么写代码,可以每隔5秒出现一句诗,点击command停止,再次点击则继续?
展开
展开全部
Dim a(5) As String, i As Integer, x As Integer
Private Sub Command1_Click()
Timer1.Enabled = Not Timer1.Enabled
End Sub
Private Sub Form_Load()
a(0) = "第1句诗词"
a(1) = "第2句诗词"
a(2) = "第3句诗词"
a(3) = "第4句诗词"
a(4) = "第5句诗词"
a(5) = "第6句诗词"
Timer1.Interval = 1000
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
If i Mod 5 = 0 Then Print a(x): x = x + 1
i = i + 1
If x > UBound(a) Then x = 0
End Sub
Private Sub Command1_Click()
Timer1.Enabled = Not Timer1.Enabled
End Sub
Private Sub Form_Load()
a(0) = "第1句诗词"
a(1) = "第2句诗词"
a(2) = "第3句诗词"
a(3) = "第4句诗词"
a(4) = "第5句诗词"
a(5) = "第6句诗词"
Timer1.Interval = 1000
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
If i Mod 5 = 0 Then Print a(x): x = x + 1
i = i + 1
If x > UBound(a) Then x = 0
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询