做了个动态演示汉诺塔的。但让不会让每一次递归延时。代码如下,请求帮助哈
Dim n As Integer
Dim a(9) As String
Dim b As String
Dim l As String
Dim k As String
Dim t As Integer
Sub hannuo(n As Integer, a As ListBox, b As ListBox, c As ListBox)
If n = 1 Then
Call moves(a, c)
Else
Call hannuo(n - 1, a, c, b)
Call moves(a, c)
Call hannuo(n - 1, b, a, c)
End If
End Sub
Sub moves(a As ListBox, c As ListBox)
k = a.List(0)
a.RemoveItem 0
c.AddItem k, 0
T1.Enabled = True
End Sub
Private Sub C1_Click()
n = 9
t = 5
T1.Enabled = True
Call hannuo(n, L1, L2, L3)
End Sub
Private Sub Form_Activate()
For i = 1 To 9
For j = 1 To i
b = b + "-"
Next j
For m = 1 To 9 - i
b = " " + b
Next m
For j = 1 To i
l = l + "-"
Next j
For m = 1 To 9 - i
l = l + " "
Next m
a(i) = b & i & l
b = ""
l = ""
Next i
For x = 1 To 9
L1.AddItem a(x)
Next x
End Sub
Private Sub T1_Timer()
t = t - 1
End Sub
vb怎么延时
答案:2 悬赏:40 手机版
解决时间 2021-07-21 17:50
- 提问者网友:浪荡绅士
- 2021-07-21 05:03
最佳答案
- 五星知识达人网友:平生事
- 2021-07-21 06:30
sleep很卡的,效果超级差,建议你用这个,给你一个简单的例子。
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Private Function delay() '想用时就调用这个过程
n = 10
Dim tm1 As Long, tm2 As Long
tm1 = timeGetTime
Do
tm2 = timeGetTime
If (tm2 - tm1) / 1000 > n Then Exit Do
DoEvents
Loop
End Function
全部回答
- 1楼网友:夜余生
- 2021-07-21 07:20
Private Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)'API
sleep 100 '延时
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯