我遇到以下一行代碼的問題。For循環問題VBA
'payFreq is input of type "Long"
Dim DF As Variant
'discFact here is input of type "Range"
DF = discFact.Value
Dim Payment_pay() As Double
ReDim Payment_pay(1 To UBound(DF))
Dim i As Long
'Fill with zeros
For i = 1 To UBound(Payment_pay)
Payment_pay(i) = 0
Next i
Dim Prev_date As Date
Dim Next_date As Date
For i = 1 To UBound(Payment_pay)
Prev_date = makeDate((i - payFreq_pay) & "M")
Next_date = makeDate(i & "M")
Next i
'Continuation of code...
的MAKEDATE功能基本上
Function makeDate(Term As String) As Date
...
End Function
試圖輸出變量Prev_date或NEXT_DATE將無法正常工作!然而,交換上限循環(UBound(Payment_pay)爲例如6,將會給出預期的返回值(一個正確的日期......)。循環迭代器「i」似乎有些問題。
幫助是非常感謝!提前
感謝, 尼克拉斯
什麼是** ** payFreq_pay?..更好地告訴你FUNC mkdate – matzone
對不起,忘了那個。現在編輯。 ** payFreq_pay **的類型是Long(輸入到fu nction)。而且,當使用例如makeDate調用它時,** makeDate **函數可以正常工作。 ** makeDate(3&「M」)**,然後返回當前日期+ 3個月 – gussilago
** Term As String ** ..「M」是字符串..但是** 3 **? – matzone