wrxdriven Posted November 5, 2003 Posted November 5, 2003 ok so i have come this far with my program. I want it to do a few more things that i just can't seem to figure out. here it is. I want to check the input to make sure they are numeric before making the schedule. I want to also make the html file look just as the listview does. And lastly the loop for the listview needs to end at 0 for the principalbalance and currently it does not. How can i adjust the loop? Thank you so much for all the time... Imports System.IO Public Class Form1 Inherits System.Windows.Forms.Form Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim sReader As IO.StreamReader '///use the System.IO.StreamReader / System.IO.StreamWriter rather than the FreeFile method. Dim path As String = "C:\syst2010\program1.cfg" Dim sLine As String Try sReader = New IO.StreamReader(New IO.FileStream(path, IO.FileMode.Open)) While Not sReader.Peek sLine = sReader.ReadLine Select Case sLine.Split("=")(0) '/// the text to the left of the = symbol. Case "loan" Me.txtLoanAmount.Text = (sLine.Split("=")(1)) '/// the value at the right of the = symbol. '/// do what you want to the value ( eg: add to textbox called Loan ) Case "interest" Me.txtInterest.Text = (sLine.Split("=")(1)) '/// and so on... Case "years" Me.txtYears.Text = (sLine.Split("=")(1)) Case "payment" Me.txtPayment.Text = (sLine.Split("=")(1)) Case "HTML" Me.txtFileLocation.Text = (sLine.Split("=")(1)) End Select End While sReader.Close() Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub Private Sub btnCalculateLoan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculateLoan.Click 'print to loan ' Make sure the Purchase Price and Down Payment have values If Me.txtInterest.Text = Text.Empty Then MessageBox.Show("Enter An Interest Value") ElseIf Me.txtYears.Text = Text.Empty Then MessageBox.Show("Enter Amount of Years") ElseIf Me.txtPayment.Text = Text.Empty Then MessageBox.Show("Enter Monthly Payment") ElseIf Me.txtFileLocation.Text = Text.Empty Then MessageBox.Show("Enter a Save Location") Else : Me.txtLoanAmount.Text = Me.txtPayment.Text / ((Me.txtInterest.Text / 1200) / (1 - (1 / (1 + (Me.txtInterest.Text / 1200)) ^ (Me.txtYears.Text * 12)))) End If 'print to lvschedule Dim myvar As Double = IsNumeric(False) Dim MonthlyPayment As Double Dim MonthlyInterest As Double Dim TotalInterest As Double Dim TotalPayments As Double Dim Months As String Dim InterestRate As Double Dim Month As String = Now.Month Dim InterestPaid As Double Dim payment As Double Dim newMonthlyInterest As Double Dim PrincipalBalance As Double Dim InterestBalance As Double Dim ListItem As New ListViewItem() ' Set local variables based on inputs Months = Me.txtYears.Text * 12 PrincipalBalance = Me.txtLoanAmount.Text InterestRate = Me.txtInterest.Text InterestPaid = (Me.txtLoanAmount.Text * (InterestRate / 1200)) payment = Me.txtPayment.Text ' Calculate the Monthly Interest MonthlyInterest = (InterestRate) / 1200 ' Calculate computation results MonthlyPayment = (-MonthlyInterest * PrincipalBalance) / _ ((MonthlyInterest + 1) ^ (-Months) - 1) ' Set "Results" fields txtLoanAmount.Text = Format(PrincipalBalance, "Currency") 'clear listview Me.lvwschedule.Items.Clear() ' Calculate the monthly values and fill the listview Dim year As String = Now.Year Dim number As Double Dim newmonth As String Dim i As Integer Dim currMonth As Integer = DateTime.Now.Month Dim currYear As Integer = DateTime.Now.Year Dim myDates(6) As String Dim principalpaid As Double Dim MyMonth As Integer Dim Name As String 'MyMonth = 4 'Name = MonthName(MyMonth, True) ' "True" returns an abbreviated name. 'MsgBox(Name) ' Name contains "Apr". 'ListItem = New ListViewItem(number) 'ListItem.SubItems.Add(year) 'ListItem.SubItems.Add(Format(Month, "short date")) 'lvschedule.Items.Add(ListItem) Do Until PrincipalBalance <= 0 number = number + 1 For i = 0 To PrincipalBalance = 1 myDates(i) = currMonth & " " & currYear If currMonth = 12 Then currYear += 1 currMonth = 1 Else currMonth += 1 End If Name = MonthName(currMonth, True) 'Select Case currMonth ' Case "1" ' currMonth = "Jan." ' Case "2" ' currMonth = "Feb." ' 'continue doing this for each month 'End Select InterestPaid = (PrincipalBalance * (1 + InterestRate / 1200)) _ - PrincipalBalance payment = Me.txtPayment.Text InterestBalance = InterestBalance + InterestPaid principalpaid = payment - InterestPaid PrincipalBalance = PrincipalBalance - principalpaid ListItem = New ListViewItem(number) ListItem.SubItems.Add(currYear) ListItem.SubItems.Add(Format(Name)) ListItem.SubItems.Add(Format(payment, "Currency")) ListItem.SubItems.Add(Format(InterestPaid, "Currency")) ListItem.SubItems.Add(Format(principalpaid, "Currency")) ListItem.SubItems.Add(Format(PrincipalBalance, "Currency")) lvwschedule.Items.Add(ListItem) Next Loop Dim filenum As Integer Dim filename As String = (Me.txtFileLocation.Text) 'Get the next available file number filenum = FreeFile() 'Open the file that we can write to FileOpen(1, filename, OpenMode.Output) 'Write to the file PrintLine(1, "<HTML>" & vbCrLf & "<BODY BGCOLOR=" & "green" & ">" & vbCrLf & "<HEAD>" & vbCrLf & "<TITLE>" _ & "Amortization Schedule" & "</TITLE>" & vbCrLf & "<link rel=" & """listview""" & Space(1) & "type=" & _ """text/css""" & Space(1) & "href=" & """cssname.css""" & ">" & vbCrLf & "</HEAD>" & vbCrLf & "<BODY>" & _ vbCrLf & "<P>" & Me.lvwschedule.Text.Clone & "</P>" & vbCrLf & "</BODY>" & vbCrLf & "</HTML>") End Sub Private Sub btnCalculatePay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculatePay.Click 'print to payment Me.txtPayment.Text = Me.txtLoanAmount.Text * ((Me.txtInterest.Text / 1200) / (1 - (1 / (1 + (Me.txtInterest.Text / 1200)) ^ (Me.txtYears.Text * 12)))) ''amortization schedule 'Dim i As Integer 'Dim year As Integer 'Dim month As String 'Dim balance As Integer 'Dim principle As String = (balance * (Me.txtInterest.Text / 1200)) 'Dim interestpaid As String = (Me.txtPayment.Text - principle) 'balance = Me.txtLoanAmount.Text 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 btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click Me.txtFileLocation.ResetText() Me.txtInterest.ResetText() Me.txtLoanAmount.ResetText() Me.txtPayment.ResetText() Me.txtYears.ResetText() Me.lvwschedule.Items.Clear() Me.txtLoanAmount.Focus() End Sub Private Sub lvschedule_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lvwschedule.SelectedIndexChanged End Sub End Class Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.