- Public Class frmMain
-
-
Private Sub btnCalulate_Click(ByVal sender As System.Object, ByVal e As
-
-
System.EventArgs) Handles btnCalulate.Click
-
-
Try
-
Dim LoanAmount As Double
-
-
Dim Payment As DoubleDim
-
InterestRate As Double
-
-
Dim Interest As DoubleDim
-
Principle As Double
-
-
Dim Years As IntegerDim
-
PaymentPeriods As Integer
-
-
Dim LoanOptionSelection As Integer
-
-
-
-
'setup loan options array with values
-
-
Dim LoanOptions(3, 2) As Double
-
-
LoanOptions(0, 0) = 7
-
-
LoanOptions(0, 1) = 5.35
-
-
LoanOptions(1, 0) = 15
-
-
LoanOptions(1, 1) = 5.5
-
-
LoanOptions(2, 0) = 30
-
-
LoanOptions(2, 1) = 5.75
-
-
-
-
'validate loan amount input
-
-
If IsNumeric(txtLoanAmount.Text) = False Then
-
MsgBox("Loan amount must be numeric. Please enter a validloan amount.")
-
-
txtLoanAmount.Clear()
-
-
txtLoanAmount.Focus()
-
-
Exit Sub
-
-
End If
-
-
-
-
'set loan variables
-
-
LoanAmount = txtLoanAmount.Text
-
-
-
-
'set proper rate and years depending on option selected by user
-
-
Select Case True
-
Case optLoanOption1.Checked
-
-
LoanOptionSelection = 0
-
Case optLoanOption2.Checked
-
-
LoanOptionSelection = 1
-
Case optLoanOption3.Checked
-
-
LoanOptionSelection = 2
-
-
End Select
-
-
-
-
'using array and loan option set the rate and years
-
-
InterestRate = LoanOptions(LoanOptionSelection, 1)
-
-
Years = LoanOptions(LoanOptionSelection, 0)
-
-
-
-
'calulate total payment periods
-
-
PaymentPeriods = Years * 12
-
-
-
-
'if rate is in percent form convert to decimal
-
-
If InterestRate > 1 Then InterestRate = InterestRate / 100
-
-
-
-
'calculate monthly payment and return value
-
-
Payment = (LoanAmount * Math.Pow((InterestRate / 12) + 1,
-
-
(PaymentPeriods)) * InterestRate / 12) / (Math.Pow(InterestRate / 12 + 1,
-
-
(PaymentPeriods)) - 1)
-
-
-
-
'display calculated payment
-
lblMonthlyPayment.Text = "Monthly Payment: " &
-
-
FormatCurrency(Payment)
-
-
-
-
'clear datagrid view control (remove all rows)
-
-
dgvLoanDetails.Rows.Clear()
-
-
-
-
'setup progress bar
-
-
pbLoan.Minimum = 1
-
-
pbLoan.Maximum = PaymentPeriods
-
-
pbLoan.Value = 1
-
-
pbLoan.Visible = True
-
-
-
-
'loop the loan payment periods displaying loan details
-
Dim i As Integer
-
-
For i = 1 To PaymentPeriods
-
-
-
-
'increase progress bar
-
-
pbLoan.Value = i
-
-
-
-
'set interest
-
-
Interest = (LoanAmount * InterestRate) / 12
-
-
-
-
'set loan amount
-
-
LoanAmount = (LoanAmount - Payment) + Interest
-
-
-
-
'set principle
-
-
Principle = Payment - Interest
-
-
-
-
'output loan details
-
-
dgvLoanDetails.Rows.Add()
-
dgvLoanDetails.Item("Month", i - 1).Value = idgvLoanDetails.Item("Payment", i - 1).Value =
-
-
FormatCurrency(Payment)
-
dgvLoanDetails.Item("Interest", i - 1).Value =
-
-
FormatCurrency(Interest)
-
dgvLoanDetails.Item("Principle", i - 1).Value =
-
-
FormatCurrency(Principle)
-
dgvLoanDetails.Item("LoanAmount", i - 1).Value =
-
-
FormatCurrency(LoanAmount)
-
-
Next
-
-
-
-
'hide progress bar now that processing is completed
-
pbLoan.Visible = False Catch ex As Exception
-
-
MsgBox("Error: " & ex.Message.ToString())
-
-
End Try
-
-
End Sub
-
-
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As
-
-
System.EventArgs) Handles btnClear.Click
-
-
-
-
'clear fields
-
-
txtLoanAmount.Clear()
-
-
optLoanOption1.Checked = True
-
-
lblMonthlyPayment.Text = ""
-
-
txtLoanAmount.Text = "200000"
-
-
dgvLoanDetails.Rows.Clear()
-
-
End Sub
-
-
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As
-
-
System.EventArgs) Handles btnExit.Click
-
-
-
-
'end program
-
-
End
-
-
End Sub
-
-
End Class
I WOULD LIKE IT TO WORK IN EXCEL
1 1945
If you want to write code for running in Excel you will need to use Visual Basic for Applications (VBA), not VB itself. Excel will not understand the VB code as you have written it.
-Stewart
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Raphael Gluck |
last post by:
Hi
I've been trying to hand code my pages, after failing in a WSYWYG editor and
giving up.
I'm almost done with the page checking, it's just i'm having a Wend error
Microsoft VBScript...
|
by: Matt |
last post by:
When the ASP statement end with a _ character, then the next line cannot
have comment ' character. Is that correct? Since I encountered the following
error:
Microsoft VBScript compilation...
|
by: andy.herrera |
last post by:
I'm getting this Error Message. Expected ';'
Please Select One:
<form name="form1"> <<------------ Error is here.
<select name="selectTrans" onChange="If (this.value == 'checkout')...
|
by: Layla |
last post by:
I thought this was ok.... but... I get the following message: COMPILE
ERROR- EXPECTED END OF STATEMENT and the "Where" is highlighted. I'm a
bit of a novice at this so any help at all would be much...
|
by: wwwursa |
last post by:
I am trying to use the Right function in a VB6 program. I have used it used many times before in other programs.
When I press the enter key after entering the code line, the word "Right" turns...
|
by: amitmool |
last post by:
hi, i have used the queue library file and try to use the template as
template <class QueueItem>
queue <QueueItem>::~queue() // line 25
{
}
template <class QueueItem>
void...
|
by: Indy |
last post by:
Hi,
I am new to VB and have some previous programming experiences.
Curently working as an IT support person and trying to write a VB 6 script to access apos database and get one of the table's...
|
by: noemailplease0001 |
last post by:
#ifndef POSITION_H_
#define POSITION_H_
class Position
{
public:
Position(std::string name, std::string name):
m_name( name), m_description(description){}
std::string toString();
private:
|
by: prw8864 |
last post by:
I can not see what is causing this error....
iterator has been defined properly, but the error seems to point to the interator type.
Errors I get with g++ svector.c++ -o svector 2> ./err_txt...
|
by: rameshjumgam |
last post by:
i am having in my code like
std::list<T*>::const_iterator iter=lst.begin();
and i am getting error
error: expected `;' before âiterâ
/root/INCLUDE/cw/gdlist.h:140: error: âiterâ was...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |