我运行一段程序的时候,数据量大就显得特别的慢,又不知道要等多久,有没有什么办法可以显示即时需要等待的时间?比如我要完成一个循环,这个循环完成需要多少时间,开始倒计时,就像我们复制文件倒计时那样
还有一个问题是,我一运行我的那个程序,如果还没算完,他就在任务管理器的应用程序一栏里显示未响应,直到它算完了才变成正在运行,请问这正常吗?会不会是我的程序写的不好才这样?
还有一个问题是,我一运行我的那个程序,如果还没算完,他就在任务管理器的应用程序一栏里显示未响应,直到它算完了才变成正在运行,请问这正常吗?会不会是我的程序写的不好才这样?
到循环计算结束的时候再用一次,两次的差就是了
例如:
for i=0 to 1000000000
x=x+1'假设为你的语句
doevents'这句加哪无所谓,在你的循环里就行.
next i
这样就不会象死掉一样了.
Dim i As Long
Dim s As String
Dim rStart As Single
Dim rTimePass As Single
Dim rTimeTotal As Single
rStart = Timer()
For i = 1 To 10000000
s = CStr(i)
'不必每个循环都刷新,只要每秒几十帧的频率即可'
If (i Mod 50000) = 0 Then
rTimePass = Timer() - rStart
rTimeTotal = rTimePass * 10000000 / i
Label1 = Format$(rTimeTotal - rTimePass, "0.000")
DoEvents
End If
Next
End Sub
Dim t1 As New clsTimeCount
t1.Mark
Dim i&
For i = 0 To 100000
DoEvents
Next
MsgBox t1.TimeCount
End Sub
clsTimeCount.cls
Option ExplicitPrivate Declare Function GetTickCount Lib "kernel32" () As Long
Private lngCurrent As LongProperty Get TimeCount() As Long
TimeCount = GetTickCount() - lngCurrent
End PropertyPublic Sub Mark()
lngCurrent = GetTickCount()
End Sub
t1 = DateAdd("s", i, Now)
While t1 > Now
DoEvents
Wend
End Sub如果要等10秒,那么代码就是
Pause 10
prg1.Visible = False
prg1.Max = 100
End SubPrivate Sub Command1_Click()
' Static variables are shared by all instances of a procedure.
Static blnProcessing As Boolean
Dim i As Long, lngCt As Long, dblDummy As Double ' Show the ProgressBar control.
prg1.Visible = True
prg1.Value = 0
' When the button is clicked, test whether it's already processing.
If blnProcessing Then
' If processing is in progress, cancel it.
blnProcessing = False
Else
Command1.Caption = "Cancel"
blnProcessing = True
' Perform a hundred million floating-point multiplications.
' After every thousand, update the progress bar and the commondbutton's caption.
Do While blnProcessing And (lngCt < 100000000)
For i = 1 To 1000
lngCt = lngCt + 1
dblDummy = lngCt * 3.14159
Next i
' The DoEvents statement allows other events to occur, including pressing this
' button a second time.
prg1.Value = lngCt / 1000000
If prg1.Value = 100 Then prg1.Visible = False
DoEvents
Loop
blnProcessing = False
Command1.Caption = "Process"
MsgBox lngCt & " multiplications were performed"
End IfEnd Sub