如何将数据从一个阵列复制到另一个阵列?

时间:2020-04-18 07:33:09

标签: arrays vba

我正在尝试将数据从CF数组移到d数组,但是我没有成功。当我在For Next之后重新保留d数组时,我仍然不成功。

这是什么问题?

Function DPB(rate As Double, ByRef CF As Variant) As Variant

Dim d() As Variant
For k = LBound(CF) To UBound(CF)  
   d(k) = CF(k) / (1 + rate) ^ (k - 1)  
Next k

2 个答案:

答案 0 :(得分:2)

自从您使用'Variant`s以来,您就可以轻松进行以下操作:

<form id="calculate" action="">
  <div>
    <div class="form-group col-md-4">
      <label for="departure"><strong>Arrival Time </strong></label>
      <?php $date = date("H:i"); ?>
      <input id="startTime" type="time" name="hour_start" value="01:00">
    </div>
    <br />
    <div class="form-group col-md-4">
      <label for="departure"><strong>Departure Time</strong></label>
      <?php $date = date("H:i"); ?>
      <input id="endTime" type="time" name="hour_end" value="01:11">
    </div>

    <p id="diff_hour"></p>
  </div>
</form>

答案 1 :(得分:1)

根据您发布的代码,我建议看看以下代码

Option Explicit

Function DPB(rate As Double, ByRef CF As Variant) As Variant

    Dim k As Long
    Dim d() As Variant
    ReDim d(LBound(CF) To UBound(CF))

    For k = LBound(CF) To UBound(CF)

        d(k) = CF(k) / (1 + rate) ^ (k - 1)

    Next k
    DPB = d
End Function

Sub test()
    Dim v(0 To 1) As Variant

    v(0) = 1
    v(1) = 2

    Dim vDat As Variant
    vDat = DPB(2, v)

End Sub