【问题标题】:Calculate percentage fill of progress bar计算进度条的百分比填充
【发布时间】:2013-02-19 11:23:11
【问题描述】:

我在 Excel VBA 中的用户窗体上设置进度条图像的错误宽度时遇到问题。

我有一个用户表单,该表单上有一个标签和一个图像。

图片最大宽度为330。

在从 1 到 intNumberOfGetRows(在本例中为 64)的循环中,我想更新图像的 width 属性以显示进度,因为大型记录集的每个 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 时,应该是填充图像的 20% 左右,这意味着图像的宽度应该是 66,所以我想出了这个:

330 * (intRecord / intNumberOfGetRows * 100) / 100

我好像忘记了我的基本数学理论,那是最好的方法吗?

感谢您对如何改进提出任何建议

菲利普

【问题讨论】:

标签: math excel progress-bar vba


【解决方案1】:

你不需要那里的那 100 个。您只希望您的进度显示您已完成(在您的示例中)总数的 13/64,总数为 330,因此您需要计算的只是 330 * (13/64):

330 * (intRecord / intNumberOfGetRows)

【讨论】:

    猜你喜欢
    • 2010-11-22
    • 2023-02-08
    • 1970-01-01
    • 2021-05-18
    • 2014-08-14
    • 1970-01-01
    • 2016-04-17
    相关资源
    最近更新 更多