请教哪个VB高手能帮小弟我写下面一个简单的多线程程序
请问哪个VB高手能帮我写下面一个简单的多线程程序
form1里有两个command,两个text。command1里的代码是这样的:
Private Sub Command1_Click()
Dim i As Single
For i = 1 To 30000
Text1.Refresh
Text1.Text = i
Next i
End Sub
command2里的代码是这样的:
Private Sub Command2_Click()
Dim j As Single
For j = 1 To 30000
Text2.Refresh
Text2.Text = j
Next j
End Sub
我的目的就是点击command1后,再点击command2,使它们能同时运行。我这样是想锻炼一下多线程的用法,请高手指导一下这样的程序应该怎么写才能实现上述功能。
------解决方案--------------------
修改你的代码,做个假多线程,实现你的要求。(注:此段代码只能由command1先启动,如果要实现不论按钮次序,代码就留给你完成了,不准完全依懒别人。)
============
Dim blCMD1, blCMD2 As Boolean
Private Sub Command1_Click()
blCMD1 = True
abcdef
blCMD1 = False
End Sub
Private Sub Command2_Click()
blCMD2 = True
End Sub
Sub abcdef()
Dim i As Single
Dim j As Single
Do
If i = 30000 And blCMD2 Then GoTo asdfasdf
Text1.Text = i
DoEvents
i = i + 1
If blCMD2 = False Then GoTo qwertyu
asdfasdf:
Text2.Text = j
j = j + 1
If j = 30000 Then Exit Do
qwertyu:
Loop
blCMD2 = False
End Sub
------解决方案--------------------
Dim blCMD1, blCMD2 As Boolean
Private Sub Command1_Click()
blCMD1 = True
abcdef
End Sub
Private Sub Command2_Click()
blCMD2 = True
abcdef
End Sub
Sub abcdef()
Dim i, j As Single
Do
If Not blCMD1 Then GoTo asdfasdf
Text1.Text = i
DoEvents
i = i + 1
If i = 30000 Then blCMD1 = False
If blCMD2 = False Then GoTo qwertyu
asdfasdf:
Text2.Text = j
DoEvents
j = j + 1
If j = 30000 Then blCMD2 = False
qwertyu:
If Not blCMD1 And Not blCMD2 Then Exit Do
Loop
End Sub
form1里有两个command,两个text。command1里的代码是这样的:
Private Sub Command1_Click()
Dim i As Single
For i = 1 To 30000
Text1.Refresh
Text1.Text = i
Next i
End Sub
command2里的代码是这样的:
Private Sub Command2_Click()
Dim j As Single
For j = 1 To 30000
Text2.Refresh
Text2.Text = j
Next j
End Sub
我的目的就是点击command1后,再点击command2,使它们能同时运行。我这样是想锻炼一下多线程的用法,请高手指导一下这样的程序应该怎么写才能实现上述功能。
------解决方案--------------------
修改你的代码,做个假多线程,实现你的要求。(注:此段代码只能由command1先启动,如果要实现不论按钮次序,代码就留给你完成了,不准完全依懒别人。)
============
Dim blCMD1, blCMD2 As Boolean
Private Sub Command1_Click()
blCMD1 = True
abcdef
blCMD1 = False
End Sub
Private Sub Command2_Click()
blCMD2 = True
End Sub
Sub abcdef()
Dim i As Single
Dim j As Single
Do
If i = 30000 And blCMD2 Then GoTo asdfasdf
Text1.Text = i
DoEvents
i = i + 1
If blCMD2 = False Then GoTo qwertyu
asdfasdf:
Text2.Text = j
j = j + 1
If j = 30000 Then Exit Do
qwertyu:
Loop
blCMD2 = False
End Sub
------解决方案--------------------
Dim blCMD1, blCMD2 As Boolean
Private Sub Command1_Click()
blCMD1 = True
abcdef
End Sub
Private Sub Command2_Click()
blCMD2 = True
abcdef
End Sub
Sub abcdef()
Dim i, j As Single
Do
If Not blCMD1 Then GoTo asdfasdf
Text1.Text = i
DoEvents
i = i + 1
If i = 30000 Then blCMD1 = False
If blCMD2 = False Then GoTo qwertyu
asdfasdf:
Text2.Text = j
DoEvents
j = j + 1
If j = 30000 Then blCMD2 = False
qwertyu:
If Not blCMD1 And Not blCMD2 Then Exit Do
Loop
End Sub