As a lot of you may know about me, i have gone back to school. This is my third semester in online classes at Rio Salado College. I began my pursuit to obtain a Bachelor of Arts and Education but with the current state of affairs in Arizona for Education and art programs getting cut. I find the desire to actually want to use what I learn and not just get to say I have a degree. So this spring semester I switched my direction to obtain a certificate in Web design.
I have been building a creating websites for years based on very little know how and feel I can better myself and Family as well as have solid work by continuing that route for the future. One of the classes I am taking is Visual Basics. This is by far the hardest class this semester and here is an example of the work. Writing and understand what software code does and can do.[codesyntax lang=”vb” title=”Loan Calculator” blockstate=”expanded”]
Public Class Form1 'Class-level constants Const dblMONTHS_YEARS As Double = 12 'Months per year Const dblNEW_RATE As Double = 0.089 ' Interest Rate , new cars Const dblUSED_RATE As Double = 0.095 ' Interest rate, used cars 'Class-level variable to hold the anual interest rate Dim dblAnnualRate As Double = dblNEW_RATE Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click Dim dblVehicleCost As Double 'Vehicle cost Dim dblDownPayment As Double 'down payment Dim intMonths As Integer 'Number of months for the loan Dim dblLoan As Double ' Amount of the loan Dim dblMonthlyPayment As Double 'Monthly Payment Dim dblInterest As Double 'Interest paid for the peroid Dim dblPinciple As Double 'principle paid for the peroid Dim intCount As Integer 'Counter for the loop Dim strOut As String 'Used to hold a lin of output 'get the vehicle cost If Double.TryParse(txtCost.Text, dblVehicleCost) Then 'Get the down payment If Double.TryParse(txtDownPayment.Text, dblDownPayment) Then 'Get the number of months If Integer.TryParse(txtMonths.Text, intMonths) Then 'calculate the loan dblLoan = dblVehicleCost - dblDownPayment 'calculate the monthly payment dblMonthlyPayment = Pmt(dblAnnualRate / dblMONTHS_YEARS, intMonths, -dblLoan) 'clear the list box Output.Items.Clear() For intCount = 1 To intMonths 'calculate the interest for this peroid dblInterest = IPmt(dblAnnualRate / dblMONTHS_YEARS, intCount, intMonths, -dblLoan) 'Calculate the principle for this peroid dblPinciple = PPmt(dblAnnualRate / dblMONTHS_YEARS, intCount, intMonths, -dblLoan) 'Start biulding the output string with the month. strOut = "Month:" & intCount.ToString() 'Add the payment amount to the output string strOut &= "Payment:" & dblMonthlyPayment.ToString("c") 'Add interest amount to the output string strOut &= "Interests:" & dblInterest.ToString("c") 'Add principle for the peroid strOut &= "Principle:" & dblPinciple.ToString("c") 'Add the output string to the list box Output.Items.Add(strOut) Next Else 'Error message for invalid months MessageBox.Show("Enter an integer for months.") End If Else 'Error message for invald down payment MessageBox.Show("Enter a numeric value for down payment.") End If Else 'Error message for invalid vehicle cost MessageBox.Show("Enter a numeric value for vehicle cost.") End If End Sub Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click 'Reset the interest rate, clear the text boxes 'and clear the list box. Set defualt interest 'rate fir the new car loan radNew.Checked = True dblAnnualRate = dblNEW_RATE lblAnnualRate.Text = dblNEW_RATE.ToString("p") txtCost.Clear() txtDownPayment.Clear() txtMonths.Clear() Output.Items.Clear() 'reset the focus to txtCost txtCost.Focus() End Sub Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click 'close the form Me.Close() End Sub Private Sub radNew_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radNew.CheckedChanged 'if the new radio button is checked, then 'the user has selected a new car loan If radNew.Checked = True Then dblAnnualRate = dblNEW_RATE lblAnnualRate.Text = dblNEW_RATE.ToString("p") End If End Sub Private Sub radUsed_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radUsed.CheckedChanged 'if the used radio button is checked, then 'the user has selected a used car loan If radUsed.Checked = True Then dblAnnualRate = dblUSED_RATE lblAnnualRate.Text = dblUSED_RATE.ToString("p") End If End Sub End Class[/codesyntax]
This code form is for a loan calculator that works well based on two tiers of interests rates. I have yet to learn how to publish the actaul working application but when i do i promise to share. Fun, fun.