i' have a program . a lending program
what i want here is to transfer the schedule.vb to loan_calculation.vb
i mean i want to have a sing form. because the project contains 2 form
what i want here to happen it that when i click the schedule button it will calculation the monthly payment
the schedule.vb generates a datagridview. what i mean is that the schedule button will compute the monthly payment like
11/14/2011 25000
12/14/2011 15000
in a datagridview.
heres the code for Loan_calculation.vb
Code to schedule.vb
what i want to happen to the program is this :
Attachment 98087
if you want to see the project here it is :
http://www.mediafire.com/?17ks7flds9fs460
what i want here is to transfer the schedule.vb to loan_calculation.vb
i mean i want to have a sing form. because the project contains 2 form
what i want here to happen it that when i click the schedule button it will calculation the monthly payment
the schedule.vb generates a datagridview. what i mean is that the schedule button will compute the monthly payment like
11/14/2011 25000
12/14/2011 15000
in a datagridview.
heres the code for Loan_calculation.vb
Code:
Public Class Loan_Calculation
Private Sub objPress(ByVal sender As Object, ByVal e As KeyPressEventArgs)
Select Case Asc(e.KeyChar)
Case 48 To 57
Case 46, 8
Case Else
e.Handled = True
End Select
End Sub
Private Sub InterestPayment()
Dim intAmount As Double = 0
Dim principal As Double = Me.txtPrincipal.Text
Dim intInterestRate As Double = Me.txtInterest.Text
Dim principalPayment As Double = 0
intAmount = (principal * intInterestRate * 0.01) / 12
principalPayment = principal / CDbl(Me.txtPeriod.Text)
txtMonthlyInterestPayment.Text = FormatCurrency(intAmount, 2)
Select Case cboLoanType.Text
Case "Loan Term"
Me.txtMonthlyPrincipalPayment.Text = principalPayment
Case "Bullet Loan"
Me.txtMonthlyPrincipalPayment.Text = "$0.00"
End Select
Dim intPay As Double = CDbl(Me.txtMonthlyInterestPayment.Text)
Dim principalpay As Double = Me.txtMonthlyPrincipalPayment.Text
Dim TotalPayment As Double = intPay + principalpay
Me.txtTotalPayment.Text = FormatCurrency(TotalPayment, 2)
End Sub
Private Sub btnCalculation_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculation.Click
If Not IsNumeric(Me.txtPrincipal.Text) Then
MsgBox("Invalid principal value.", MsgBoxStyle.Exclamation, "Invalid Value")
Return
End If
If Not IsNumeric(Me.txtPeriod.Text) Then
MsgBox("Invalid period value.", MsgBoxStyle.Exclamation, "Invalid Period")
Return
End If
If Not IsNumeric(Me.txtInterest.Text) Then
MsgBox("Invalid interest rate value.", MsgBoxStyle.Exclamation, "Invalid Interest Rate")
Return
End If
If cboLoanType.Text.Trim = "" Then
MsgBox("Invalid loan type", MsgBoxStyle.Exclamation, "Invalid Loan Type")
Exit Sub
End If
InterestPayment()
End Sub
Private Sub txtPrincipal_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPrincipal.KeyPress
objPress(sender, e)
End Sub
Private Sub txtInterest_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtInterest.KeyPress
objPress(sender, e)
End Sub
Private Sub txtPeriod_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPeriod.KeyPress
objPress(sender, e)
End Sub
Private Sub btnSchedule_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSchedule.Click
Schedule.Principal = Me.txtPrincipal.Text
Schedule.InterestRate = Me.txtInterest.Text
Schedule.LoanType = Me.cboLoanType.Text
Schedule.ValueDate = Me.dtpValuedate.Value
Schedule.Period = Me.txtPeriod.Text
Schedule.Show()
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub Loan_Calculation_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.cboLoanType.Sorted = True
End Sub
End Class
Code:
Public Class Schedule
Dim dPrincipal As Double = 0
Dim dIntInterestRate As Double = 0
Dim iPeriod As Integer
Dim dtValueDate As Date
Dim sType As String = ""
Public WriteOnly Property Principal() As Double
Set(ByVal value As Double)
dPrincipal = value
End Set
End Property
Public WriteOnly Property InterestRate() As Double
Set(ByVal value As Double)
dIntInterestRate = value
End Set
End Property
Public WriteOnly Property Period() As Double
Set(ByVal value As Double)
iPeriod = value
End Set
End Property
Public WriteOnly Property ValueDate() As Date
Set(ByVal value As Date)
dtValueDate = value
End Set
End Property
Public WriteOnly Property LoanType() As String
Set(ByVal value As String)
sType = value
End Set
End Property
Private Sub GenerateScheule()
Dim monthlyInt As Double = 0
Dim monthlyPrincipal As Double = 0
Dim dtDate As Date
Dim total As Double
monthlyInt = (dPrincipal * dIntInterestRate * 0.01) / 12
monthlyPrincipal = dPrincipal / iPeriod
If sType = "Bullet Loan" Then
total = dPrincipal + monthlyInt
For i As Integer = 1 To iPeriod
dtDate = dtValueDate.AddMonths(i)
If i <> iPeriod Then
dgvLoanSchedule.Rows.Add(i, Format(dtDate, "dd/MMM/yyyy"), FormatCurrency(monthlyInt, 2), FormatCurrency(0, 2), FormatCurrency(monthlyInt, 2))
Else
dgvLoanSchedule.Rows.Add(i, Format(dtDate, "dd/MMM/yyyy"), FormatCurrency(monthlyInt, 2), FormatCurrency(dPrincipal, 2), FormatCurrency(total, 2))
End If
Next
Else
For i As Integer = 1 To iPeriod
dtDate = dtValueDate.AddMonths(i)
total = monthlyPrincipal + monthlyInt
Me.dgvLoanSchedule.Rows.Add(i, Format(dtDate, "dd/MMM/yyyy"), FormatCurrency(monthlyInt, 2), FormatCurrency(monthlyPrincipal, 2), FormatCurrency(total, 2))
dPrincipal -= monthlyPrincipal
monthlyPrincipal = dPrincipal / iPeriod
monthlyInt = (dPrincipal * dIntInterestRate * 0.01) / 12
Next
End If
End Sub
Private Sub Schedule_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.lblPrincipal.Text = FormatCurrency(dPrincipal, 2)
Me.lblPeriod.Text = iPeriod
Me.lblInterestRate.Text = dIntInterestRate
Me.lblLoanType.Text = sType
Me.lblValueDate.Text = dtValueDate
Me.lblMaturityDate.Text = dtValueDate.AddMonths(iPeriod)
GenerateScheule()
End Sub
Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBack.Click
Loan_Calculation.Show()
Me.Hide()
End Sub
Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
Me.Close()
End Sub
End Class
Attachment 98087
if you want to see the project here it is :
http://www.mediafire.com/?17ks7flds9fs460