F
Frank Dulk
I am creating an application to calculate the loan of a value with monthly
payments and interests. I know that the function exists PMT that makes that,
but I need one that calculates considering the values for useful days and to
inform the date for better payment.
Already ta everything "almost" ready, until it works but it happens the
following mistake.
I created a function to verify the day it is not a bank holiday, if it goes,
it shows the first useful day. This function is perfect.
The function that calculates the value of the portion is the following:
Pagamento(Valor Currency, Portions Integer, Interest, PrimeiroPagamento
Dates Them) Currency
If I define the date of first payment for 01/11/03, I call the function:
ProximoDiaUtil(primeiropagamento)
The function sees that 01/11 are not useful day and it defines the date for
03/11/03 that it is one Monday.
However, starting from the moment that I use that function, the variable
PrimeiroPagamento that before was 01/11/03 become it fastens 03/11/03 and
all the other references are used starting from this date.
The payments instead of they be like this, 03/11/03, 01/12/03 and 02/01/04
are all for the 3 of every month.
I don't use in any part of the code
PrimeiroPagamento=ProximoDiaUtil(PrimeiroPagamento), but after the first it
GOES, Access understands as if I had defined.
This is the function that calculates the interest
Public Function Pagamento(Valor As Currency, Parcelas As Integer, Juro,
ByRef PrimeiroPagamento As Date) As Currency
ReDim Dias(Parcelas) As Integer
ReDim Vencimentos(Parcelas)
Dim ParcelaLiquida As Currency
Dim ValorParcela As Currency
Dim i As Integer
ParcelaLiquida = Valor / Parcelas
' Here the variable is 01/11/2003
For i = 2 To Parcelas
Dias(1) = DateDiff("d", Date, ProximoDiaUtil(PrimeiroPagamento))
Dias(i) = DateDiff("d", Date, ProximoDiaUtil(DateAdd("m", i - 1,
PrimeiroPagamento)))
A partir daqui a variável fica fica com valor 03/11/2003
Vencimentos(1) = ProximoDiaUtil(PrimeiroPagamento)
Vencimentos(i) = DateAdd("m", i - 1, PrimeiroPagamento)
Next
For i = 1 To Parcelas
ValorParcela = ValorParcela + ParcelaLiquida * Dias(i) * Juro / 3000
Next
Pagamento = (ValorParcela + Valor) / Parcelas
' It shows the values in the Box of Listing
Forms!Formulário1!Lista56.RowSource = "Vencimento;Valor;Dias"
For i = 1 To Parcelas
Forms!Formulário1!Lista56.RowSource = Forms!Formulário1!Lista56.RowSource +
";" & Format(Vencimentos(i), "dd/mm/yy") & ";" & Format((ValorParcela +
Valor) / Parcelas, "Currency") & ";" & CStr(Dias(i))
Next
End Function
payments and interests. I know that the function exists PMT that makes that,
but I need one that calculates considering the values for useful days and to
inform the date for better payment.
Already ta everything "almost" ready, until it works but it happens the
following mistake.
I created a function to verify the day it is not a bank holiday, if it goes,
it shows the first useful day. This function is perfect.
The function that calculates the value of the portion is the following:
Pagamento(Valor Currency, Portions Integer, Interest, PrimeiroPagamento
Dates Them) Currency
If I define the date of first payment for 01/11/03, I call the function:
ProximoDiaUtil(primeiropagamento)
The function sees that 01/11 are not useful day and it defines the date for
03/11/03 that it is one Monday.
However, starting from the moment that I use that function, the variable
PrimeiroPagamento that before was 01/11/03 become it fastens 03/11/03 and
all the other references are used starting from this date.
The payments instead of they be like this, 03/11/03, 01/12/03 and 02/01/04
are all for the 3 of every month.
I don't use in any part of the code
PrimeiroPagamento=ProximoDiaUtil(PrimeiroPagamento), but after the first it
GOES, Access understands as if I had defined.
This is the function that calculates the interest
Public Function Pagamento(Valor As Currency, Parcelas As Integer, Juro,
ByRef PrimeiroPagamento As Date) As Currency
ReDim Dias(Parcelas) As Integer
ReDim Vencimentos(Parcelas)
Dim ParcelaLiquida As Currency
Dim ValorParcela As Currency
Dim i As Integer
ParcelaLiquida = Valor / Parcelas
' Here the variable is 01/11/2003
For i = 2 To Parcelas
Dias(1) = DateDiff("d", Date, ProximoDiaUtil(PrimeiroPagamento))
Dias(i) = DateDiff("d", Date, ProximoDiaUtil(DateAdd("m", i - 1,
PrimeiroPagamento)))
A partir daqui a variável fica fica com valor 03/11/2003
Vencimentos(1) = ProximoDiaUtil(PrimeiroPagamento)
Vencimentos(i) = DateAdd("m", i - 1, PrimeiroPagamento)
Next
For i = 1 To Parcelas
ValorParcela = ValorParcela + ParcelaLiquida * Dias(i) * Juro / 3000
Next
Pagamento = (ValorParcela + Valor) / Parcelas
' It shows the values in the Box of Listing
Forms!Formulário1!Lista56.RowSource = "Vencimento;Valor;Dias"
For i = 1 To Parcelas
Forms!Formulário1!Lista56.RowSource = Forms!Formulário1!Lista56.RowSource +
";" & Format(Vencimentos(i), "dd/mm/yy") & ";" & Format((ValorParcela +
Valor) / Parcelas, "Currency") & ";" & CStr(Dias(i))
Next
End Function