怎样知道执行某个子程序or函数or窗体需要多长时间,并且用进度栏显示!

解决方案 »

  1.   

    点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
      

  2.   

    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
      

  3.   

    楼上的代码不对吧:
    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
      

  4.   

    如果用timer控件控制,应该先测试代码执行的时间:在代码段开始时Debug.print time,结束时Debug.print time,就可以得到运行时间.
    还可以根据代码执行的进度控制.比如说你的程序时间主要用在循环上,就可以根据循环变量控制进度条的值.
      

  5.   

    一般是要通过timer来控制的。