2013-02-19 76 views
1

我在Excel VBA中的用戶窗體上設置我的進度欄圖像的worrect寬度時遇到了問題。計算進度條的百分比填充

我有一個用戶表單,並在該表單上是一個標籤和一個圖像。

圖像的最大寬度爲330

在我的循環1〜intNumberOfGetRows(在這種情況下64)我要更新的圖像的寬度屬性顯示作爲的每1000記錄塊進展大的記錄集被放入一個數組並寫入一個csv文件。

這是我的代碼:

For intRecord = 1 To intNumberOfGetRows + 1 ' outer loop 

    ' put the data in an array and print to file 
    arrContacts = adoRsMailshotAccConData.GetRows(intRows) 

    With fsOutputFile 

     For iDx = 0 To UBound(arrContacts, 2) 
      .WriteLine arrContacts(0, iDx) 
     Next 

     '.Close 
    End With 

    sMsg = "Number " & intRecord & " of " & intNumberOfGetRows 
    Application.StatusBar = sMsg 

    With frmProgress 
     .lblProgress.Caption = sMsg 
     .imgProgress.Width = (intRecord/intNumberOfGetRows) * 330 
     DoEvents 
     .Repaint 
    End With 

    DoEvents 
Next 

當intRecord是13,那麼就應該是填充圖像,這意味着圖像的寬度應爲66的20%左右,所以我想出了這個:

330 *(intRecord/intNumberOfGetRows * 100)/ 100

看起來好像我忘記了基本的數學理論,因此,最好的方法是什麼?

感謝,關於如何提高這個

菲利普

+2

另一個提示:你不用標籤,而是使用文本框來給它一個很好的效果。看到這個例子http://stackoverflow.com/questions/10782394/pop-up-the-excel-statusbar/10787496#10787496 – 2013-02-19 11:34:42

+0

啊,但我的形象從淺藍色到深藍色的漸變效果,看起來真的spiffy :) – 2013-02-19 16:59:19

回答

3

你不需要在那裏的數百任何建議。你只是想你的進步,以顯示你做了(在你的例子),佔總數的13/64ths,總爲330,所以你需要計算爲330 *(13/64):

330 * (intRecord/intNumberOfGetRows)

+0

謝謝,這簡單得多! – 2013-02-19 11:32:51

+0

+ 1很好:) – 2013-02-19 11:53:35