Dim NowRC As Long, MaxRC As Long, SSTime As Long Dim ModSS As Long Private Sub Command1_Click() SSTime = 0 '初始化秒的数量 Timer1.Interval = 100 '设置Timer控件100豪秒触发一次事件,开始5秒可以快点 Timer1.Enabled = True ProgressBar1.Max = 10 '滚动条控件的最大范围 ProgressBar1.Value = 0 '滚动条控件的当前值 Label1.Caption = "正在评估要处理的时间..." AllSS = 0 MaxRC = 9999999 '设计要生成的数据总数 For X = 1 To MaxRC DoEvents NowRC = X '设置当前的数据位置 '你生成数据的过程
Next X
Label1.Caption = "完成处理." Timer1.Enabled = False End SubPrivate Sub Timer1_Timer() SSTime = SSTime + 1 If SSTime >= 10 Then '1秒钟以后开始处理正常进度 ModSS = Format(MaxRC / (NowRC / SSTime), "0.00") ProgressBar1.Max = ModSS ProgressBar1.Value = SSTime Label1.Caption = "已用:" & Format(SSTime / 10, "0.00") & " 剩余:" & Format((ModSS - SSTime) / 10, "0.00") & "秒/共需" & Format(ModSS / 10, "0.00") & "秒" Else ProgressBar1.Value = SSTime Mod 10 End If End Sub程序你可以先试验,然后再改代码
Dim NowRC As Long, MaxRC As Long, SSTime As Long
Dim ModSS As Long
Private Sub Command1_Click()
SSTime = 0 '初始化秒的数量
Timer1.Interval = 100 '设置Timer控件100豪秒触发一次事件,开始5秒可以快点
Timer1.Enabled = True
ProgressBar1.Max = 10 '滚动条控件的最大范围
ProgressBar1.Value = 0 '滚动条控件的当前值
Label1.Caption = "正在评估要处理的时间..."
AllSS = 0
MaxRC = 9999999 '设计要生成的数据总数
For X = 1 To MaxRC
DoEvents
NowRC = X '设置当前的数据位置
'你生成数据的过程
Next X
Label1.Caption = "完成处理."
Timer1.Enabled = False
End SubPrivate Sub Timer1_Timer()
SSTime = SSTime + 1
If SSTime >= 10 Then
'1秒钟以后开始处理正常进度
ModSS = Format(MaxRC / (NowRC / SSTime), "0.00")
ProgressBar1.Max = ModSS
ProgressBar1.Value = SSTime
Label1.Caption = "已用:" & Format(SSTime / 10, "0.00") & " 剩余:" & Format((ModSS - SSTime) / 10, "0.00") & "秒/共需" & Format(ModSS / 10, "0.00") & "秒"
Else
ProgressBar1.Value = SSTime Mod 10
End If
End Sub程序你可以先试验,然后再改代码
牛人啊,不过现在又出现问题:我在pictureBox 上画了个进度条,让picturebox.visible=false ,当生成数据时置
picturebox.visible=true ,结果却看不到 picturebox 只能看到一个进度条在动,太难看了,在单步跟踪时
picturebox 就能出现,怎么解决啊?谢谢了!是不是生成的速度太快了,picturebox 来不及显示?
这就说明你已经看到了你的 picturebox,所谓的看不到是什么?
是他的边框吗?Picture1.Refresh
Doevents再看不见边框我也不知道怎么回事了,而且是不是边框我都不肯定,这样猜很难猜的。
裸奔、跪谢!就是用Picture1.Refresh 这样就可以看到picturebox了,否则就一个进度条在动,昨天花了至少6个小时时间也没搞定!