2013-02-19 73 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