2
Reply

Problem with dividend program

locojava21

locojava21

May 15 2005 12:15 AM
2k
I have nfi why this program crashes whenever i hit process. The files are in the right directory etc, it just won't work! the code is here: Option Explicit On Option Strict On Public Class frmShareDividend Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents btnProcessdata As System.Windows.Forms.Button Friend WithEvents lblTotalMr As System.Windows.Forms.Label Friend WithEvents lblTotalMRs As System.Windows.Forms.Label Friend WithEvents lblAnsMr As System.Windows.Forms.Label Friend WithEvents lblAnsMrs As System.Windows.Forms.Label Friend WithEvents lstOutput As System.Windows.Forms.ListBox Private Sub InitializeComponent() Me.btnProcessdata = New System.Windows.Forms.Button Me.lblTotalMr = New System.Windows.Forms.Label Me.lblTotalMRs = New System.Windows.Forms.Label Me.lblAnsMr = New System.Windows.Forms.Label Me.lblAnsMrs = New System.Windows.Forms.Label Me.lstOutput = New System.Windows.Forms.ListBox Me.SuspendLayout() ' 'btnProcessdata ' Me.btnProcessdata.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.btnProcessdata.Location = New System.Drawing.Point(240, 48) Me.btnProcessdata.Name = "btnProcessdata" Me.btnProcessdata.Size = New System.Drawing.Size(136, 40) Me.btnProcessdata.TabIndex = 1 Me.btnProcessdata.Text = "Process Data" ' 'lblTotalMr ' Me.lblTotalMr.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.lblTotalMr.Location = New System.Drawing.Point(16, 312) Me.lblTotalMr.Name = "lblTotalMr" Me.lblTotalMr.Size = New System.Drawing.Size(448, 23) Me.lblTotalMr.TabIndex = 2 Me.lblTotalMr.Text = "Total tax adjusted value of Mr Savitup’s shares :" ' 'lblTotalMRs ' Me.lblTotalMRs.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.lblTotalMRs.Location = New System.Drawing.Point(16, 344) Me.lblTotalMRs.Name = "lblTotalMRs" Me.lblTotalMRs.Size = New System.Drawing.Size(376, 24) Me.lblTotalMRs.TabIndex = 3 Me.lblTotalMRs.Text = "Total tax adjusted value of Mrs Savitup’s shares :" ' 'lblAnsMr ' Me.lblAnsMr.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.lblAnsMr.Location = New System.Drawing.Point(384, 312) Me.lblAnsMr.Name = "lblAnsMr" Me.lblAnsMr.Size = New System.Drawing.Size(144, 23) Me.lblAnsMr.TabIndex = 4 ' 'lblAnsMrs ' Me.lblAnsMrs.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.lblAnsMrs.Location = New System.Drawing.Point(384, 344) Me.lblAnsMrs.Name = "lblAnsMrs" Me.lblAnsMrs.Size = New System.Drawing.Size(144, 23) Me.lblAnsMrs.TabIndex = 5 ' 'lstOutput ' Me.lstOutput.Location = New System.Drawing.Point(24, 112) Me.lstOutput.Name = "lstOutput" Me.lstOutput.Size = New System.Drawing.Size(600, 173) Me.lstOutput.TabIndex = 6 ' 'frmShareDividend ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(656, 462) Me.Controls.Add(Me.lstOutput) Me.Controls.Add(Me.lblAnsMrs) Me.Controls.Add(Me.lblAnsMr) Me.Controls.Add(Me.lblTotalMRs) Me.Controls.Add(Me.lblTotalMr) Me.Controls.Add(Me.btnProcessdata) Me.Name = "frmShareDividend" Me.Text = "Share Dividends Reporting Program" Me.ResumeLayout(False) End Sub #End Region Private Sub btnProcessdata_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProcessdata.Click Dim fmtStr As String = "{0,5} {1,20} {2,10} {3,15} {4,10} {5,15}" Dim srestreamreader As IO.StreamReader Dim intNumComp As Integer Dim strOwnerCode As String Dim strCompanyCodeMF As String Dim strCompanyName As String Dim strOutput As String Dim amount_aftertax As Double Dim TaxStatus As String Dim strCompanyCodeDF As String Dim shares As Integer Dim amount As Double Dim taxrate As Decimal = 0.78D Dim amount_b4tax As Double If IO.File.Exists("D:\MONASH UNIVERSITY\IMS1906-Business Programing Fundamentals\Assignments\Assignment 02\Tax Return\bin\companies.txt") Then srestreamreader = IO.File.OpenText("D:\MONASH UNIVERSITY\IMS1906-Business Programing Fundamentals\Assignments\Assignment 02\Tax Return\bin\companies.txt") intNumComp = Convert.ToInt32(srestreamreader.ReadLine) End If Do While intNumComp > 0 strOwnerCode = srestreamreader.ReadLine() strCompanyCodeMF = srestreamreader.ReadLine() strCompanyName = srestreamreader.ReadLine() If strOwnerCode = "1" Then srestreamreader = IO.File.OpenText("D:\MONASH UNIVERSITY\IMS1906-Business Programing Fundamentals\Assignments\Assignment 02\Tax Return\bin\dividedns1.txt") strOwnerCode = srestreamreader.ReadLine() strCompanyCodeDF = srestreamreader.ReadLine() If strCompanyCodeDF = strCompanyCodeMF Then shares = Convert.ToInt32(srestreamreader.ReadLine) amount = Convert.ToDouble(srestreamreader.ReadLine) TaxStatus = srestreamreader.ReadLine() amount_b4tax = shares * amount If TaxStatus = "Y" Then amount_aftertax = shares * amount Else amount_aftertax = shares * amount * taxrate End If End If Else srestreamreader = IO.File.OpenText("D:\MONASH UNIVERSITY\IMS1906-Business Programing Fundamentals\Assignments\Assignment 02\Tax Return\bin\dividends2.txt") strCompanyCodeDF = srestreamreader.ReadLine() If strCompanyCodeDF = strCompanyCodeMF Then shares = Convert.ToInt32(srestreamreader.ReadLine) amount = Convert.ToDouble(srestreamreader.ReadLine) TaxStatus = srestreamreader.ReadLine() amount_b4tax = shares * amount If TaxStatus = "Y" Then TaxStatus = srestreamreader.ReadLine() amount_aftertax = shares * amount Else TaxStatus = srestreamreader.ReadLine() amount_aftertax = shares * amount * taxrate End If End If End If Loop ' Use the format string above to format name, age and phone number strOutput = String.Format(fmtStr, strCompanyCodeDF, strCompanyName, strOwnerCode, amount_b4tax, TaxStatus, amount_aftertax) ' Display numbers to show columns, and on next line the formatted string lstOutput.Items.Add("Code Company Name Owner Received Taxed? After-Tax" & _ vbNewLine & strOutput) End Sub End Class

Answers (2)