Windows Forms - Finanças
Module Financas

Cálculo básico de juros compostos

    ''' <summary>
    ''' mFV = Valor futuro ou Valor emprestado FV
    ''' mpag = valor pago amortizando divida mpay
    ''' taxa = taxa de juros anual em porcentagem Rate
    ''' nPer = Número de períodos ou número de pagamentos
    ''' mPV = divida restante, montante restante da dívida PV
    ''' mVT = Valor total pago até o momento VT
    ''' qPg = True = Pagamento feito no início do período Due
    ''' os parametros definidos como ByRef é porque podem ter seus valores alterados dentro desta função
    ''' </summary>
    Public Sub ExecutaCalculo(mpag As Double, ByRef mfv As Double, taxa As Double, nPer As String, ByRef mPV As Double, qPG As Boolean, ByRef mVT As Double)
        Dim vrate As Double
        Dim vper As Double
        Dim vpv As Double
        Dim vfv As Double
        Dim vdue As Double
        Dim vvt As Double

        If Val(mpag) = 0 And Val(mfv) = 0 Then
            MsgBox("O pagamento Anual e valor futuro zerados...Um dos dois deve ser preenchido.")
        End If

        If Val(taxa) = 0 Then
            MsgBox("Taxa inválida")
        End If

        If Val(nPer) = 0 Then
            MsgBox("O número de pagamentos ou períodos é inválido")
        End If

        'vrate = Convert.ToDouble(taxa) 'se o valor vier de um textbox
        vrate = taxa
        vrate = vrate / 100 / 12 'convertendo a taxa para o período - mensal

        'vper = Convert.ToDouble(nPer)
        vper = nPer

        'If mPV <> "" Then 'se o valor vier de um textbox
        'vpv = Convert.ToDouble(mPV)
        'Else
        'vpv = 0
        'End If

        ''se o valor vier de um textbox
        'If mFV <> "" Then
        'vfv = Convert.ToDouble(mFV)
        'Else
        'vfv = 0
        'End If

        If qPG = True Then
            vdue = 1
        Else
            vdue = 0
        End If

        If vpv = 0 Then
            vpv = -Pmt(vrate, vper, vfv, vdue)
            mPV = vpv.ToString("###,###.00")
            vvt = vpv * vper
            mVT = (vvt).ToString("###,###.00")
        Else
            vfv = Pmt(vrate, vper, vpv, vfv, vdue)
            mfv = CStr(vfv)
        End If


    End Sub


End Module