那也不行,msgbox 不是界面吗? 贴一个我以前的'模块中的 Public playflag As Boolean Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Declare Function CreateThread Lib "kernel32" (lpThreadAttributes As Any, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadID As Long) As Long Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Public Sub AsyncThread() '不要要该过程中操作任何界面,不然程序会死的 Dim i As Long Open "d:\temp.txt" For Output As #1 For i = i To 10000 If playflag Then Print #1, "第" & i & "次" Sleep (100) Else Close #1 Exit Sub End If Next i Close #1 End Sub 'form中的Private Sub Command1_Click() mol.playflag = False End Sub Private Sub cmdplay_Click() playflag = True Dim hThread As Long, hThreadID As Long hThread = CreateThread(ByVal 0&, ByVal 0&, AddressOf AsyncThread, ByVal 0&, ByVal 0&, hThreadID) '另外开一线程 CloseHandle hThread End SubPrivate Sub Command2_Click() Dim i As Integer ProgressBar1.Max = 10000 For i = 1 To 10000 ProgressBar1.Value = i Next i End Sub
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Declare Function CreateThread Lib "kernel32" (lpThreadAttributes As Any, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadID As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Public Sub AsyncThread() '不要要该过程中操作任何界面,不然程序会死的
Dim i As Long
Open "d:\temp.txt" For Output As #1
For i = i To 10000
If playflag Then
Print #1, "第" & i & "次"
Sleep (100)
Else
Close #1
Exit Sub
End If
Next i
Close #1
End Sub
'form中的Private Sub Command1_Click()
mol.playflag = False
End Sub
Private Sub cmdplay_Click()
playflag = True
Dim hThread As Long, hThreadID As Long
hThread = CreateThread(ByVal 0&, ByVal 0&, AddressOf AsyncThread, ByVal 0&, ByVal 0&, hThreadID) '另外开一线程
CloseHandle hThread
End SubPrivate Sub Command2_Click()
Dim i As Integer
ProgressBar1.Max = 10000
For i = 1 To 10000
ProgressBar1.Value = i
Next i
End Sub