?
Solved

In a rut in building this Financial Calculator

Posted on 2003-03-25
22
Medium Priority
?
351 Views
Last Modified: 2012-08-13
I am attempting to create a financial calculator that computes the present value of a lump sum, the future value of a lump sum, and a payment.  I am trying to make it where the code in the program should enable the text boxes necessary for input and disable the text box that will store the output based on the selected desired result from checking the appropriate option in the file menu. Of course only one at a time so they will be used as input and output text boxes, respectively.  I’ve placed an error handler statement, let me know if I should have more.

Thanks so much in advance for everyone’s help!


Below is what I have so far!


VERSION 5.00
Begin VB.Form Form1
   Caption         =   "Unit 1 Financial Calculator"
   ClientHeight    =   3330
   ClientLeft      =   165
   ClientTop       =   735
   ClientWidth     =   5445
   LinkTopic       =   "Form1"
   ScaleHeight     =   3330
   ScaleWidth      =   5445
   StartUpPosition =   3  'Windows Default
   Begin VB.TextBox lbl_ShowFutureValue
      Height          =   285
      Left            =   1560
      TabIndex        =   10
      Top             =   2760
      Width           =   1815
   End
   Begin VB.CommandButton Cmd_EvaluateValue
      Caption         =   "Evaluate"
      Height          =   495
      Left            =   3720
      TabIndex        =   4
      Top             =   2520
      Width           =   1215
   End
   Begin VB.TextBox txt_InputPresentValue
      Height          =   285
      Left            =   1560
      TabIndex        =   3
      Top             =   2130
      Width           =   1815
   End
   Begin VB.TextBox txt_InputPayments
      Height          =   285
      Left            =   1560
      TabIndex        =   2
      Top             =   1530
      Width           =   1815
   End
   Begin VB.TextBox txt_InputNumberOfYears
      Height          =   285
      Left            =   1560
      TabIndex        =   1
      Top             =   930
      Width           =   1815
   End
   Begin VB.TextBox txt_InputInterestRate
      Height          =   285
      Left            =   1560
      TabIndex        =   0
      Top             =   330
      Width           =   1815
   End
   Begin VB.Label Label5
      Caption         =   "Future Value:"
      Height          =   255
      Left            =   480
      TabIndex        =   9
      Top             =   2760
      Width           =   975
   End
   Begin VB.Label Label4
      Caption         =   "Present Value:"
      Height          =   255
      Left            =   480
      TabIndex        =   8
      Top             =   2160
      Width           =   1095
   End
   Begin VB.Label Label3
      Caption         =   "Payments:"
      Height          =   255
      Left            =   480
      TabIndex        =   7
      Top             =   1560
      Width           =   855
   End
   Begin VB.Label Label2
      Caption         =   "Period:"
      Height          =   255
      Left            =   480
      TabIndex        =   6
      Top             =   960
      Width           =   495
   End
   Begin VB.Label Label1
      Caption         =   "Interest Rate:"
      Height          =   255
      Left            =   480
      TabIndex        =   5
      Top             =   360
      Width           =   975
   End
   Begin VB.Menu File
      Caption         =   "&File"
      Begin VB.Menu mnuFileExit
         Caption         =   "E&xit"
      End
   End
   Begin VB.Menu Calculate
      Caption         =   "&Calculate"
      Begin VB.Menu mnuCalculatePayment
         Caption         =   "&Payment"
         Checked         =   -1  'True
      End
      Begin VB.Menu mnuCalculatePresentValue
         Caption         =   "&Present Value"
         Checked         =   -1  'True
      End
      Begin VB.Menu mnuCalculateFutureValue
         Caption         =   "&Future Value"
         Checked         =   -1  'True
      End
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
 'Program is written to evaluate and produce Payment, Future Value or Present value
 'of a given Value Amount based on the selected option desired.
 Option Explicit

Private Sub mnuPayment_Click()          'Select to enable Payment as desired output.
   txtPayment.Text = Format(txtPayment.Text, "Currency", 2)
   
End Sub

Private Sub mnuPresentValue_Click()     'Select to enable Present value as desired output.
 

End Sub

Private Sub mnuFuturevalue_Click()      'Select to enable Future Value as desired output.
 

End Sub

Private Sub Cmd_EvaluateValue_Click()   'Evaluate & calculate the desired results.
 
 On Error GoTo ErrHandler
 
 Dim Exponent As Double                 'Declarations
 Dim FutureValue As Currency
 Dim InterestRate As Double
 Dim NumberOfYears As Integer
 Dim Payments As Currency
 Dim PresentValue As Currency
 
 Payments = Val(txt_InputPayments.Text)
 InterestRate = Val(Format$(txt_InputInterestRate.Text / 100, "##0.00"))
 NumberOfYears = Val(txt_InputNumberOfYears.Text)
 PresentValue = Val(txt_InputPresentValue.Text)
 Exponent = Exp(Payments * NumberOfYears)
 
 FutureValue = PresentValue * (1 + (InterestRate / Payments)) ^ Exponent
 lbl_ShowFutureValue.Caption = Format$(FutureValue, "Currency")
 
 Exit Sub
 
ErrHandler:
 MsgBox "Please enter valid data into fields.", vbExclamation
 
End Sub


Private Sub mnuFileExit_Click()
  Unload Me

0
Comment
Question by:GlobalFax
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
22 Comments
 
LVL 10

Expert Comment

by:aeklund
ID: 8207524
To start out, put some debugging into your Error Handler..


msgbox err.number & ": " & err.description

This will let you know what the error is so you can fix it...
0
 
LVL 2

Expert Comment

by:Jacamar
ID: 8207530
Ok, if I were to do this, I would start the program with all textboxes enabled.  In the Text_Change() event, I would have a procedure that would check the values in all the textboxes.  When there were X-1 Valid Entries (X is number of Textboxes), I would enable the Command button, and disable the other textbox.  Once the compute button is hit, I would enable all textboxes.
0
 
LVL 1

Author Comment

by:GlobalFax
ID: 8207739
Thanks Aeklund!

Jacamar, thanks!  But you'll have to excuse my lack of knowledge in VB programming, I so far have created what you see as a work of miracle.  Please elaborate on where would I place the procedure to check the values in the textboxes.  As well as what you mention as enabling and disabling textboxes when enabling the command button appropriately, I am lost.  Thanks again in advance!.

I've taken on a project that is out of my scope at work, but now regret accepting the task.  Again thanks for all you assistance.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Expert Comment

by:supunr
ID: 8207761
VERSION 5.00
Begin VB.Form Form1
   Caption         =   "Unit 1 Financial Calculator"
   ClientHeight    =   3330
   ClientLeft      =   165
   ClientTop       =   735
   ClientWidth     =   5445
   LinkTopic       =   "Form1"
   ScaleHeight     =   3330
   ScaleWidth      =   5445
   StartUpPosition =   3  'Windows Default
   Begin VB.TextBox lbl_ShowFutureValue
      Height          =   285
      Left            =   1560
      TabIndex        =   10
      Top             =   2760
      Width           =   1815
   End
   Begin VB.CommandButton Cmd_EvaluateValue
      Caption         =   "Evaluate"
      Height          =   495
      Left            =   3720
      TabIndex        =   4
      Top             =   2520
      Width           =   1215
   End
   Begin VB.TextBox txt_InputPresentValue
      Height          =   285
      Left            =   1560
      TabIndex        =   3
      Top             =   2130
      Width           =   1815
   End
   Begin VB.TextBox txt_InputPayments
      Height          =   285
      Left            =   1560
      TabIndex        =   2
      Top             =   1530
      Width           =   1815
   End
   Begin VB.TextBox txt_InputNumberOfYears
      Height          =   285
      Left            =   1560
      TabIndex        =   1
      Top             =   930
      Width           =   1815
   End
   Begin VB.TextBox txt_InputInterestRate
      Height          =   285
      Left            =   1560
      TabIndex        =   0
      Top             =   330
      Width           =   1815
   End
   Begin VB.Label Label5
      Caption         =   "Future Value:"
      Height          =   255
      Left            =   480
      TabIndex        =   9
      Top             =   2760
      Width           =   975
   End
   Begin VB.Label Label4
      Caption         =   "Present Value:"
      Height          =   255
      Left            =   480
      TabIndex        =   8
      Top             =   2160
      Width           =   1095
   End
   Begin VB.Label Label3
      Caption         =   "Payments:"
      Height          =   255
      Left            =   480
      TabIndex        =   7
      Top             =   1560
      Width           =   855
   End
   Begin VB.Label Label2
      Caption         =   "Period:"
      Height          =   255
      Left            =   480
      TabIndex        =   6
      Top             =   960
      Width           =   495
   End
   Begin VB.Label Label1
      Caption         =   "Interest Rate:"
      Height          =   255
      Left            =   480
      TabIndex        =   5
      Top             =   360
      Width           =   975
   End
   Begin VB.Menu File
      Caption         =   "&File"
      Begin VB.Menu mnuFileExit
         Caption         =   "E&xit"
      End
   End
   Begin VB.Menu Calculate
      Caption         =   "&Calculate"
      Begin VB.Menu mnuCalculatePayment
         Caption         =   "&Payment"
      End
      Begin VB.Menu mnuCalculatePresentValue
         Caption         =   "&Present Value"
      End
      Begin VB.Menu mnuCalculateFutureValue
         Caption         =   "&Future Value"
         Checked         =   -1  'True
      End
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'Program is written to evaluate and produce Payment, Future Value or Present value
'of a given Value Amount based on the selected option desired.
Option Explicit

Private Sub Cmd_EvaluateValue_Click()   'Evaluate & calculate the desired results.

On Error GoTo ErrHandler
 
Dim Exponent As Double                 'Declarations
Dim FutureValue As Currency
Dim InterestRate As Double
Dim NumberOfYears As Integer
Dim Payments As Currency
Dim PresentValue As Currency

Payments = Val(txt_InputPayments.Text)
InterestRate = Val(Format$(Val(txt_InputInterestRate.Text) / 100, "##0.00"))
NumberOfYears = Val(txt_InputNumberOfYears.Text)
PresentValue = Val(txt_InputPresentValue.Text)
Exponent = Exp(Payments * NumberOfYears)

If (mnuCalculateFutureValue.Checked = True) Then
    FutureValue = PresentValue * (1 + (InterestRate / Payments)) ^ Exponent
    lbl_ShowFutureValue.Text = Format$(FutureValue, "Currency")
ElseIf (mnuCalculatePayment.Checked = True) Then
    Payments = InterestRate / ((FutureValue / PresentValue) ^ (1 / Exponent) - 1)
    txt_InputPayments.Text = Format$(FutureValue, "Currency")
ElseIf (mnuCalculatePresentValue.Checked = True) Then
    PresentValue = FutureValue / (1 + (InterestRate / Payments)) ^ Exponent
    txt_InputPresentValue.Text = Format$(FutureValue, "Currency")
End If

Exit Sub

ErrHandler:
MsgBox "Please enter valid data into fields.", vbExclamation

End Sub


Private Sub Form_Load()
    mnuCalculatePresentValue_Click
End Sub

Private Sub mnuCalculateFutureValue_Click()
    mnuCalculateFutureValue.Checked = True
    mnuCalculatePayment.Checked = False
    mnuCalculatePresentValue.Checked = False
    txt_InputPayments.Enabled = True
    txt_InputPresentValue.Enabled = True
    lbl_ShowFutureValue.Enabled = False
End Sub

Private Sub mnuCalculatePayment_Click()
    mnuCalculateFutureValue.Checked = False
    mnuCalculatePayment.Checked = True
    mnuCalculatePresentValue.Checked = False
    txt_InputPayments.Enabled = False
    txt_InputPresentValue.Enabled = True
    lbl_ShowFutureValue.Enabled = True
End Sub

Private Sub mnuCalculatePresentValue_Click()
    mnuCalculateFutureValue.Checked = False
    mnuCalculatePayment.Checked = False
    mnuCalculatePresentValue.Checked = True
    txt_InputPayments.Enabled = True
    txt_InputPresentValue.Enabled = False
    lbl_ShowFutureValue.Enabled = True
End Sub

Private Sub mnuFileExit_Click()
 Unload Me
End Sub

' Good Luck!
0
 
LVL 1

Author Comment

by:GlobalFax
ID: 8207853
Thanks Supunr!   That was awesome.

When I select "Payment" and enter the required appropriately, I get $0.00 as the "Payment".  Is there something I missed?  No matter wht values I apply, I get $0.00.  Likewise when i select "present Value".

Andd when I selecct "Future Value", it displays the value I place in "Present value"

Thanks Again, in advance!
0
 
LVL 11

Expert Comment

by:supunr
ID: 8207895
I am working on your code now....
is this part correct?

Exponent = Exp(Payments * NumberOfYears)

FutureValue = PresentValue * (1 + (InterestRate / Payments)) ^ Exponent

should that be....

FutureValue = PresentValue * (1 + (InterestRate / Payments)) ^ (Payments * NumberOfYears)


Exp(Payments * NumberOfYears) means e^(Payments * NumberOfYears).

I am not sure if this is correct???

0
 
LVL 11

Expert Comment

by:supunr
ID: 8207926
refer to this page...
http://dcary.csun.edu/csun/OLQuiz/calculator.htm
what is the exact formula? (not in code form)
0
 
LVL 11

Expert Comment

by:supunr
ID: 8207950
actually this might be a good link...don't know if this is the relavent formulas you looking for...
http://www.fpctools.com/teachme.html
0
 
LVL 1

Author Comment

by:GlobalFax
ID: 8208019
Excellent links!

These are the functions of the syntax respectively:

PV(rate, nper, pmt[, fv{, type)])

FV(rate, nper, pmt[, pv[, type]])

Pmt(rate, nper, pv[, fv[, type]])


But I don't see where the problem is in the code.
0
 
LVL 11

Expert Comment

by:supunr
ID: 8208046
here is the update calculate module using Annuities formula


Private Sub Cmd_EvaluateValue_Click()   'Evaluate & calculate the desired results.

On Error GoTo ErrHandler
 
Dim A As Double
Dim R As Double
Dim n As Double
Dim Q As Double
Dim P As Double

Q = Val(txt_InputPayments.Text)
R = Val(Format$(1 + Val(txt_InputInterestRate.Text) / 100, "##0.00"))
n = Val(txt_InputNumberOfYears.Text) ' number of payments (not necessorily number of years.  If payed monthly for 2 years, then number of payments = 24
P = Val(txt_InputPresentValue.Text)

' A = PR^n - Q(R^n-1)/(R-1) ' - annuaties formula
If (mnuCalculateFutureValue.Checked = True) Then
    A = (P * (R ^ n)) - (Q * ((R ^ n) - 1) / (R - 1))
    lbl_ShowFutureValue.Text = Format$(A, "Currency")
ElseIf (mnuCalculatePayment.Checked = True) Then
    Q = (P * (R ^ n) - A) * (R - 1) / ((R ^ n) - 1)
    txt_InputPayments.Text = Format$(Q, "Currency")
ElseIf (mnuCalculatePresentValue.Checked = True) Then
    P = (A + (Q * ((R ^ n) - 1) / (R - 1))) / (R ^ n)
    txt_InputPresentValue.Text = Format$(P, "Currency")
End If

Exit Sub

ErrHandler:
MsgBox "Please enter valid data into fields.", vbExclamation

End Sub

' Note that period should be changed to number of payments

Good Luck!
0
 
LVL 1

Author Comment

by:GlobalFax
ID: 8214751
Below is the current code as you posted, I am getting a "Runtime error 6" overflow at the payment line of the first "Else If".


Option Explicit

Private Sub Cmd_EvaluateValue_Click()   'Evaluate & calculate the desired results.

'On Error GoTo ErrHandler

Dim FutureValue As Double
Dim InterestRate As Double
Dim NumberOfPayments As Double
Dim Payment As Double
Dim PresentValue As Double

Payment = Val(txt_InputPayment.Text)
InterestRate = Val(Format$(1 + Val(txt_InputInterestRate.Text) / 100, "##0.00"))
NumberOfPayments = Val(txt_InputNumberOfPayments.Text) ' number of payments (not necessorily number of years.  If payed monthly for 2 years, then number of payments = 24
PresentValue = Val(txt_InputPresentValue.Text)

' A = PR^n - Payment(R^n-1)/(R-1) ' - annuaties formula
If (mnuCalculateFutureValue.Checked = True) Then
   FutureValue = (PresentValue * (InterestRate ^ NumberOfPayments)) - (Payment * ((InterestRate ^ NumberOfPayments) - 1) / (InterestRate - 1))
   lbl_ShowFutureValue.Text = Format$(FutureValue, "Currency")
ElseIf (mnuCalculatePayment.Checked = True) Then
   Payment = (PresentValue * (InterestRate ^ NumberOfPayments) - FutureValue) * (InterestRate - 1) / ((InterestRate ^ NumberOfPayments) - 1)
   txt_InputPayment.Text = Format$(Payment, "Currency")
ElseIf (mnuCalculatePresentValue.Checked = True) Then
   PresentValue = (FutureValue + (Payment * ((InterestRate ^ NumberOfPayments) - 1) / (InterestRate - 1))) / (InterestRate ^ NumberOfPayments)
   txt_InputPresentValue.Text = Format$(PresentValue, "Currency")
End If

Exit Sub

End Sub



Private Sub Form1_Load()
   mnuCalculatePresentValue_Click
End Sub

Private Sub mnuCalculateFutureValue_Click()
   mnuCalculateFutureValue.Checked = True
   mnuCalculatePayment.Checked = False
   mnuCalculatePresentValue.Checked = False
   txt_InputPayment.Enabled = True
   txt_InputPresentValue.Enabled = True
   lbl_ShowFutureValue.Enabled = False
End Sub

Private Sub mnuCalculatePayment_Click()
   mnuCalculateFutureValue.Checked = False
   mnuCalculatePayment.Checked = True
   mnuCalculatePresentValue.Checked = False
   txt_InputPayment.Enabled = False
   txt_InputPresentValue.Enabled = True
   lbl_ShowFutureValue.Enabled = True
End Sub

Private Sub mnuCalculatePresentValue_Click()
   mnuCalculateFutureValue.Checked = False
   mnuCalculatePayment.Checked = False
   mnuCalculatePresentValue.Checked = True
   txt_InputPayment.Enabled = True
   txt_InputPresentValue.Enabled = False
   lbl_ShowFutureValue.Enabled = True
End Sub

Private Sub mnuFileExit_Click()
Unload Me
End Sub

0
 
LVL 11

Expert Comment

by:supunr
ID: 8214954
you don't have much options other than having an error handle for this situation.  Enable the Error Handler

Private Sub Cmd_EvaluateValue_Click()   'Evaluate & calculate the desired results.

On Error GoTo ErrHandler

Dim FutureValue As Double
Dim InterestRate As Double
Dim NumberOfPayments As Double
Dim Payment As Double
Dim PresentValue As Double

Payment = Val(txt_InputPayment.Text)
InterestRate = Val(Format$(1 + Val(txt_InputInterestRate.Text) / 100, "##0.00"))
NumberOfPayments = Val(txt_InputNumberOfPayments.Text) ' number of payments (not necessorily number of years.  If payed monthly for 2 years, then number of payments = 24
PresentValue = Val(txt_InputPresentValue.Text)

' A = PR^n - Payment(R^n-1)/(R-1) ' - annuaties formula
If (mnuCalculateFutureValue.Checked = True) Then
  FutureValue = (PresentValue * (InterestRate ^ NumberOfPayments)) - (Payment * ((InterestRate ^ NumberOfPayments) - 1) / (InterestRate - 1))
  lbl_ShowFutureValue.Text = Format$(FutureValue, "Currency")
ElseIf (mnuCalculatePayment.Checked = True) Then
  Payment = (PresentValue * (InterestRate ^ NumberOfPayments) - FutureValue) * (InterestRate - 1) / ((InterestRate ^ NumberOfPayments) - 1)
  txt_InputPayment.Text = Format$(Payment, "Currency")
ElseIf (mnuCalculatePresentValue.Checked = True) Then
  PresentValue = (FutureValue + (Payment * ((InterestRate ^ NumberOfPayments) - 1) / (InterestRate - 1))) / (InterestRate ^ NumberOfPayments)
  txt_InputPresentValue.Text = Format$(PresentValue, "Currency")
End If

Exit Sub

ErrHandler:
if (Err.Number = 6) then
If (mnuCalculateFutureValue.Checked = True) Then
  lbl_ShowFutureValue.Text = "Overflow"
ElseIf (mnuCalculatePayment.Checked = True) Then
  txt_InputPayment.Text = "Overflow"
ElseIf (mnuCalculatePresentValue.Checked = True) Then
  txt_InputPresentValue.Text = "Overflow"
End If
End if
On error goto 0
End Sub

' this is what normal calculators do as well if the number is out of the limits of the calculator.  
' if you still want more accuarcy, then you have to work in logarithmics.
0
 
LVL 1

Author Comment

by:GlobalFax
ID: 8221697
I've run this although since this debug error 6 is occurring, it is an a debur error loop where it displays "overflow" all the time.

0
 
LVL 11

Expert Comment

by:supunr
ID: 8221739
in visual basic IDE, goto the Tools->Options menu.  then select the general tab.  Make sure "Break in class module" error trapping option is selected (rather than "Break on all errors" option) and you have enabled the error trapping as I have mentioned in the previous comment.
0
 
LVL 1

Author Comment

by:GlobalFax
ID: 8221827
"Break in class module" was and is selected, and I have enabled the error trapping.
0
 
LVL 11

Expert Comment

by:supunr
ID: 8221843
could you post the complete form code and the numbers you have tried.
0
 
LVL 11

Expert Comment

by:supunr
ID: 8221862
OH, one other thing....interest rate should be per period than per year....you might need an option called, number of payments, payments per year option.

I will correct your code if you could post the complete form code.
0
 
LVL 1

Author Comment

by:GlobalFax
ID: 8221913
'Program is written to evaluate and produce Payment, Future Value or Present value
'of a given Value Amount based on the selected option desired.
Option Explicit

Private Sub Cmd_EvaluateValue_Click()   'Evaluate & calculate the desired results.

On Error GoTo ErrHandler

Dim FutureValue As Currency
Dim InterestRate As Double
Dim NumberOfPayments As Integer
Dim Payment As Currency
Dim PresentValue As Currency
Dim Exponent As Double

Payment = Val(txt_InputPayment.Text)
InterestRate = Val(Format$(1 + Val(txt_InputInterestRate.Text) / 100, "##0.00"))
NumberOfPayments = Val(txt_InputNumberOfPayments.Text) ' number of payments (not necessorily number of years.  If payed monthly for 2 years, then number of payments = 24
PresentValue = Val(txt_InputPresentValue.Text)
Exponent = Exp(Payment * NumberOfPayments)


If (mnuCalculateFutureValue.Checked = True) Then
   FutureValue = (PresentValue * (InterestRate ^ NumberOfPayments)) - (Payment * ((InterestRate ^ NumberOfPayments) - 1) / (InterestRate - 1))
   lbl_ShowFutureValue.Text = Format$(FutureValue, "Currency")
ElseIf (mnuCalculatePayment.Checked = True) Then
   Payment = (PresentValue * (InterestRate ^ NumberOfPayments) - FutureValue) * (InterestRate - 1) / ((InterestRate ^ NumberOfPayments) - 1)
   txt_InputPayment.Text = Format$(Payment, "Currency")
ElseIf (mnuCalculatePresentValue.Checked = True) Then
   PresentValue = (FutureValue + (Payment * ((InterestRate ^ NumberOfPayments) - 1) / (InterestRate - 1))) / (InterestRate ^ NumberOfPayments)
   txt_InputPresentValue.Text = Format$(PresentValue, "Currency")
End If

Exit Sub

ErrHandler:
If (Err.Number = 6) Then
If (mnuCalculateFutureValue.Checked = True) Then
 lbl_ShowFutureValue.Text = "Overflow"
ElseIf (mnuCalculatePayment.Checked = True) Then
 txt_InputPayment.Text = "Overflow"
ElseIf (mnuCalculatePresentValue.Checked = True) Then
 txt_InputPresentValue.Text = "Overflow"
End If
End If
On Error GoTo 0
End Sub


Private Sub Form1_Load()
   mnuCalculatePresentValue_Click
End Sub

Private Sub mnuCalculateFutureValue_Click()
   mnuCalculateFutureValue.Checked = True
   mnuCalculatePayment.Checked = False
   mnuCalculatePresentValue.Checked = False
   txt_InputPayment.Enabled = True
   txt_InputPresentValue.Enabled = True
   lbl_ShowFutureValue.Enabled = False
End Sub

Private Sub mnuCalculatePayment_Click()
   mnuCalculateFutureValue.Checked = False
   mnuCalculatePayment.Checked = True
   mnuCalculatePresentValue.Checked = False
   txt_InputPayment.Enabled = False
   txt_InputPresentValue.Enabled = True
   lbl_ShowFutureValue.Enabled = True
End Sub

Private Sub mnuCalculatePresentValue_Click()
   mnuCalculateFutureValue.Checked = False
   mnuCalculatePayment.Checked = False
   mnuCalculatePresentValue.Checked = True
   txt_InputPayment.Enabled = True
   txt_InputPresentValue.Enabled = False
   lbl_ShowFutureValue.Enabled = True
End Sub

Private Sub mnuFileExit_Click()
    Dim intUserResponse As Integer
    Const conBtns As Integer = _
        vbYesNo + vbExclamation + vbDefaultButton1 + vbApplicationModal
    intUserResponse = MsgBox("Do you want to exit?", conBtns)
    If intUserResponse = vbYes Then
        End
    End If
   
End Sub
0
 
LVL 11

Accepted Solution

by:
supunr earned 2000 total points
ID: 8222056
VERSION 5.00
Begin VB.Form Form1
   Caption         =   "Unit 1 Financial Calculator"
   ClientHeight    =   3705
   ClientLeft      =   165
   ClientTop       =   735
   ClientWidth     =   5340
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   ScaleHeight     =   3705
   ScaleWidth      =   5340
   StartUpPosition =   3  'Windows Default
   Begin VB.TextBox txt_NoOfPaymentsPerYear
      Height          =   285
      Left            =   2280
      TabIndex        =   2
      Text            =   "1"
      Top             =   1440
      Width           =   1455
   End
   Begin VB.TextBox txt_FutureValue
      Height          =   285
      Left            =   2280
      TabIndex        =   5
      Top             =   3120
      Width           =   1455
   End
   Begin VB.CommandButton Cmd_EvaluateValue
      Caption         =   "Evaluate"
      Default         =   -1  'True
      Height          =   495
      Left            =   3960
      TabIndex        =   6
      Top             =   3000
      Width           =   1215
   End
   Begin VB.TextBox txt_PresentValue
      Height          =   285
      Left            =   2280
      TabIndex        =   4
      Top             =   2490
      Width           =   1455
   End
   Begin VB.TextBox txt_Payment
      Height          =   285
      Left            =   2280
      TabIndex        =   3
      Top             =   1890
      Width           =   1455
   End
   Begin VB.TextBox txt_NoOfPayments
      Height          =   285
      Left            =   2280
      TabIndex        =   1
      Top             =   930
      Width           =   1455
   End
   Begin VB.TextBox txt_InputInterestRatePA
      Height          =   285
      Left            =   2280
      TabIndex        =   0
      Top             =   330
      Width           =   1455
   End
   Begin VB.Label Label6
      Caption         =   "Number of payments per year:"
      Height          =   255
      Left            =   120
      TabIndex        =   12
      Top             =   1440
      Width           =   2415
   End
   Begin VB.Label Label5
      Caption         =   "Future Value:"
      Height          =   255
      Left            =   120
      TabIndex        =   11
      Top             =   3120
      Width           =   975
   End
   Begin VB.Label Label4
      Caption         =   "Present Value:"
      Height          =   255
      Left            =   120
      TabIndex        =   10
      Top             =   2520
      Width           =   1095
   End
   Begin VB.Label Label3
      Caption         =   "Payment amount:"
      Height          =   255
      Left            =   120
      TabIndex        =   9
      Top             =   1920
      Width           =   855
   End
   Begin VB.Label Label2
      Caption         =   "Total Number of payments"
      Height          =   255
      Left            =   120
      TabIndex        =   8
      Top             =   960
      Width           =   1935
   End
   Begin VB.Label Label1
      Caption         =   "Interest Rate (pa):"
      Height          =   255
      Left            =   120
      TabIndex        =   7
      Top             =   360
      Width           =   1335
   End
   Begin VB.Menu File
      Caption         =   "&File"
      Begin VB.Menu mnuFileExit
         Caption         =   "E&xit"
      End
   End
   Begin VB.Menu Calculate
      Caption         =   "&Calculate"
      Begin VB.Menu mnuCalculatePayment
         Caption         =   "&Payment"
      End
      Begin VB.Menu mnuCalculatePresentValue
         Caption         =   "&Present Value"
      End
      Begin VB.Menu mnuCalculateFutureValue
         Caption         =   "&Future Value"
         Checked         =   -1  'True
      End
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'Program is written to evaluate and produce Payment, Future Value or Present value
'of a given Value Amount based on the selected option desired.
Option Explicit

Private Sub Cmd_EvaluateValue_Click()   'Evaluate & calculate the desired results.

    On Error GoTo ErrHandler
   
    Dim FutureValue As Currency
    Dim InterestRate As Double
    Dim NumberOfPayments As Integer
    Dim Payment As Currency
    Dim PresentValue As Currency
'    Dim Exponent As Double
   
    Payment = Val(txt_Payment.Text)
    InterestRate = Val(1 + (Val(txt_InputInterestRatePA.Text) / Val(txt_NoOfPaymentsPerYear.Text)) / 100)
    NumberOfPayments = Val(txt_NoOfPayments.Text)
    PresentValue = Val(txt_PresentValue.Text)
    FutureValue = Val(txt_FutureValue.Text)
'    Exponent = Exp(Payment * NumberOfPayments)
   
   
    If (mnuCalculateFutureValue.Checked = True) Then
        FutureValue = (PresentValue * (InterestRate ^ NumberOfPayments)) - (Payment * ((InterestRate ^ NumberOfPayments) - 1) / (InterestRate - 1))
        txt_FutureValue.Text = Format$(FutureValue, "Currency")
    ElseIf (mnuCalculatePayment.Checked = True) Then
        Payment = (PresentValue * (InterestRate ^ NumberOfPayments) - FutureValue) * (InterestRate - 1) / ((InterestRate ^ NumberOfPayments) - 1)
        txt_Payment.Text = Format$(Payment, "Currency")
    ElseIf (mnuCalculatePresentValue.Checked = True) Then
        PresentValue = (FutureValue + (Payment * ((InterestRate ^ NumberOfPayments) - 1) / (InterestRate - 1))) / (InterestRate ^ NumberOfPayments)
        txt_PresentValue.Text = Format$(PresentValue, "Currency")
    End If
   
    Exit Sub
   
ErrHandler:
    If (Err.Number = 6) Then
        If (mnuCalculateFutureValue.Checked = True) Then
            txt_FutureValue.Text = "Overflow"
        ElseIf (mnuCalculatePayment.Checked = True) Then
            txt_Payment.Text = "Overflow"
        ElseIf (mnuCalculatePresentValue.Checked = True) Then
            txt_PresentValue.Text = "Overflow"
        End If
    End If
    On Error GoTo 0
End Sub

Private Sub Form_Load()
    mnuCalculatePresentValue_Click
End Sub

Private Sub mnuCalculateFutureValue_Click()
    mnuCalculateFutureValue.Checked = True
    mnuCalculatePayment.Checked = False
    mnuCalculatePresentValue.Checked = False
    txt_Payment.Enabled = True
    txt_PresentValue.Enabled = True
    txt_FutureValue.Enabled = False
End Sub

Private Sub mnuCalculatePayment_Click()
    mnuCalculateFutureValue.Checked = False
    mnuCalculatePayment.Checked = True
    mnuCalculatePresentValue.Checked = False
    txt_Payment.Enabled = False
    txt_PresentValue.Enabled = True
    txt_FutureValue.Enabled = True
End Sub

Private Sub mnuCalculatePresentValue_Click()
    mnuCalculateFutureValue.Checked = False
    mnuCalculatePayment.Checked = False
    mnuCalculatePresentValue.Checked = True
    txt_Payment.Enabled = True
    txt_PresentValue.Enabled = False
    txt_FutureValue.Enabled = True
End Sub

Private Sub mnuFileExit_Click()
   Dim intUserResponse As Integer
   Const conBtns As Integer = _
       vbYesNo + vbExclamation + vbDefaultButton1 + vbApplicationModal
   intUserResponse = MsgBox("Do you want to exit?", conBtns)
   If intUserResponse = vbYes Then
       End
   End If
End Sub

' no of payments per year....
yearly = 1
half yearly = 2
quartaly = 4
monthly = 12
fortnightly = 26
weekly = 52
daily = 365
' Good Luck!
0
 
LVL 1

Author Comment

by:GlobalFax
ID: 8222230
Excellent stuff, I see where and why you made the modifications.   I can't thank you enough......for your continued help these past few nights.  If I could, I'd double the points.  

Thanks again, for all your help!

Signed,

Greatful!
0
 
LVL 11

Expert Comment

by:supunr
ID: 8222287
Thanks for the points.
0
 
LVL 1

Author Comment

by:GlobalFax
ID: 8222298
You certainly earned every one, and then some!

0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question