【问题标题】:do not add the data to array if data is equal to zero in vb6如果数据在 vb6 中为零,则不要将数据添加到数组中
【发布时间】:2013-08-28 07:03:35
【问题描述】:

这是我的代码:

i=0
ReDim Preserve cashflowValues(i)
cashflowValues(0) = loanAmount
Do Until adors.EOF
      ReDim Preserve cashflowValues(i)
      IF adors!CashFlow <> 0 Then
          cashflowValues(i) = adors!CashFlow
          End If
          adors.MoveNext
          i = i + 1
    Loop

但仍将零值添加到数组中。我的代码有什么问题?我错过了什么吗?

提前感谢提供帮助的人! :)

【问题讨论】:

    标签: arrays vb.net vb6


    【解决方案1】:

    i 只有在将值添加到数组时才需要递增。类似的东西

    IF adors!CashFlow <> 0 Then
        cashflowValues(i) = adors!CashFlow
        i = i + 1
    End If
    adors.MoveNext
    

    【讨论】:

    • 我还要提一下,我认为循环中的 ReDim Preserve cashflowValues(i) 行只应在添加新项目时调用。另一方面,我会尽量避免使用 ReDim Preserve,并且尽可能预先分配数组的大小(使用 Preserve 是一个缓慢的操作)。或者,使用 VBA.Collection 类。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-10
    • 2014-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多