点VB菜单的/工程/部件/控件/选microsoft windows common controls,再把一个ProgressBar和Command控件加到你的窗体中,运行以下代码。 Private Sub Command1_Click() Dim aa, bb As Integer aa = 2 For bb = 1 To 100 Debug.Print i Debug.Print aa aa = aa + 500 ProgressBar1.Value = bb Next End Sub
sub form_load() ProgressBar1.min=1 ProgressBar1.max=100 progressbar1.value=0
end sub Private Sub Command1_Click()1 timer1.enable=true timer1.interval=1000 End Subsub timer1_time() if progressbar1.value=progressbar1.max then timer1.enable=false progressbar1.value=progressbar1.value +1 end if end sub
楼上的代码不对吧: 1 你已设了ProgressBar1.min=1,而后又赋值它等于0(progressbar1.value=0),这样会出错的. 2 Private Sub Command1_Click()1应为Private Sub Command1_Click() 3 timer1.enable=true应为timer1.Enabled=true 4 sub timer1_time() 应改为 private sub timer1_timer() 5 时钟控件中代码关键一句else代码漏掉了,timer1.enable也应改为timer1.Enabled=true. if progressbar1.value=progressbar1.max then timer1.Enabled=false else progressbar1.value=progressbar1.value +1 end if
Private Sub Command1_Click()
Dim aa, bb As Integer
aa = 2
For bb = 1 To 100
Debug.Print i
Debug.Print aa
aa = aa + 500
ProgressBar1.Value = bb
Next
End Sub
ProgressBar1.min=1
ProgressBar1.max=100
progressbar1.value=0
end sub
Private Sub Command1_Click()1
timer1.enable=true
timer1.interval=1000
End Subsub timer1_time()
if progressbar1.value=progressbar1.max then
timer1.enable=false
progressbar1.value=progressbar1.value +1
end if
end sub
1 你已设了ProgressBar1.min=1,而后又赋值它等于0(progressbar1.value=0),这样会出错的.
2 Private Sub Command1_Click()1应为Private Sub Command1_Click()
3 timer1.enable=true应为timer1.Enabled=true
4 sub timer1_time() 应改为 private sub timer1_timer()
5 时钟控件中代码关键一句else代码漏掉了,timer1.enable也应改为timer1.Enabled=true.
if progressbar1.value=progressbar1.max then
timer1.Enabled=false
else
progressbar1.value=progressbar1.value +1
end if
还可以根据代码执行的进度控制.比如说你的程序时间主要用在循环上,就可以根据循环变量控制进度条的值.