If in a loop ?

WineSnob

Not Bright but TENACIOUS
Local time
Today, 17:42
Joined
Aug 9, 2010
Messages
211
I am trying to change a calculation every 6 years if a variable is true. Here is what I have. (see the comments after If nInflYear = 5 Then)

There is a test function below using the arguments. The correct answer will be 5000,5000,5000,5000,5000,5796.37. So every 6th year the calc changes.

Public Function zCalcIncome(nYears As Integer, nStartingYear As Integer, ClientMonthlyInc As Currency, InflationFactor As Double, nInflYear As Double) As Currency
Dim i As Integer
For xYear = nStartingYear To (nStartingYear + (nYears - 1))
If nInflYear = 1 Then
StartIncomeAmt = ClientMonthlyInc * (1 + InflationFactor) ^ (xYear - 1)

'MsgBox "Year " & xYears & " " & StartIncomeAmt
Debug.Print "Year: " & xYear & " " & "MonthlyIncome: " & StartIncomeAmt
End If


If nInflYear = 5 Then
StartIncomeAmt = ClientMonthlyInc '***Until Year 6,11,16,(every 5 years LETS CALL IT fYears) Then the calculation will be
'StartIncomeAmt = ClientMonthlyInc * (1 + InflationFactor) ^ (fYears - 1)

'MsgBox "Year " & xYears & " " & StartIncomeAmt
Debug.Print "Year: " & xYear & " " & "MonthlyIncome: " & StartIncomeAmt

End If

zCalcIncome = StartIncomeAmt

Next xYear
End Function

________________________________________________


Function GetMonthincome()
''(nYears, nStartingYear, ClientMonthlyInc, InflationFactor , nInflYear
Debug.Print zCalcIncome(6, 1, 5000, 0.03, 5)
End Function
 
Years 1,2,3,4,5 the calculation will be
If nInflYear = 5 Then
StartIncomeAmt = ClientMonthlyInc

at year 6 calculation will be
StartIncomeAmt = ClientMonthlyInc * (1 + InflationFactor) ^ ( 6 - 1)

When I loop and get to year 6 the calculation will change
How do I count the loops and at year 6 change the calc?????????
 
Years 1,2,3,4,5 the calculation will be
If nInflYear = 5 Then
StartIncomeAmt = ClientMonthlyInc

at year 6 calculation will be
StartIncomeAmt = ClientMonthlyInc * (1 + InflationFactor) ^ ( 6 - 1)

When I loop and get to year 6 the calculation will change
How do I count the loops and at year 6 change the calc?????????

Well xYear increments by 1 each time it hits the next xYear line, assuming you start at a value of 1 you could use something like

Code:
If (xYear mod 6 ) = 0 Then
     StartIncomeAmt = ClientMonthlyInc * (1 + InflationFactor) ^ ( 6 - 1)
Else
     StartIncomeAmt = ClientMonthlyInc
End if
 
try this:
If (xYear-1) mod 5 = 0
 

Users who are viewing this thread

Back
Top Bottom