VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



reading and writing and computing payroll data for school project

by Prentice Hall (1 Submission)
Category: Encryption
Compatability: VB.NET
Difficulty: Unknown Difficulty
Originally Published: Fri 8th June 2007
Date Added: Mon 8th February 2021
Rating: (1 Votes)

reading and writing and computing payroll data for school project

Rate reading and writing and computing payroll data for school project



    Inherits System.Windows.Forms.Form
    Const FileFilter As String = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
    Dim PayrollReader As System.IO.StreamReader
    Dim PayrollWriter As System.IO.StreamWriter

#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 GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
    Friend WithEvents Label6 As System.Windows.Forms.Label
    Friend WithEvents GroupBox3 As System.Windows.Forms.GroupBox
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents Label7 As System.Windows.Forms.Label
    Friend WithEvents Label9 As System.Windows.Forms.Label
    Friend WithEvents btnQuit As System.Windows.Forms.Button
    Friend WithEvents btnCompute As System.Windows.Forms.Button
    Friend WithEvents cdlOpenFile As System.Windows.Forms.OpenFileDialog
    Friend WithEvents cdlSaveFile As System.Windows.Forms.SaveFileDialog
    Friend WithEvents btnRead As System.Windows.Forms.Button
    Friend WithEvents btnSave As System.Windows.Forms.Button
    Friend WithEvents GroupBox4 As System.Windows.Forms.GroupBox
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents txtName As System.Windows.Forms.TextBox
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents mskSSN As AxMSMask.AxMaskEdBox
    Friend WithEvents lblIncome As System.Windows.Forms.Label
    Friend WithEvents txtCurrentIncome As System.Windows.Forms.TextBox
    Friend WithEvents lblPrevIncome As System.Windows.Forms.Label
    Friend WithEvents lblCurrentIncome As System.Windows.Forms.Label
    Friend WithEvents lblPrevWithholdings As System.Windows.Forms.Label
    Friend WithEvents lblCurrentWithholdings As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
        Me.GroupBox1 = New System.Windows.Forms.GroupBox()
        Me.lblIncome = New System.Windows.Forms.Label()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.GroupBox2 = New System.Windows.Forms.GroupBox()
        Me.txtCurrentIncome = New System.Windows.Forms.TextBox()
        Me.Label6 = New System.Windows.Forms.Label()
        Me.GroupBox3 = New System.Windows.Forms.GroupBox()
        Me.lblPrevIncome = New System.Windows.Forms.Label()
        Me.Label9 = New System.Windows.Forms.Label()
        Me.lblCurrentIncome = New System.Windows.Forms.Label()
        Me.Label7 = New System.Windows.Forms.Label()
        Me.lblPrevWithholdings = New System.Windows.Forms.Label()
        Me.Label4 = New System.Windows.Forms.Label()
        Me.lblCurrentWithholdings = New System.Windows.Forms.Label()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.btnQuit = New System.Windows.Forms.Button()
        Me.btnCompute = New System.Windows.Forms.Button()
        Me.cdlOpenFile = New System.Windows.Forms.OpenFileDialog()
        Me.cdlSaveFile = New System.Windows.Forms.SaveFileDialog()
        Me.btnRead = New System.Windows.Forms.Button()
        Me.btnSave = New System.Windows.Forms.Button()
        Me.GroupBox4 = New System.Windows.Forms.GroupBox()
        Me.mskSSN = New AxMSMask.AxMaskEdBox()
        Me.Label5 = New System.Windows.Forms.Label()
        Me.txtName = New System.Windows.Forms.TextBox()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.GroupBox1.SuspendLayout()
        Me.GroupBox2.SuspendLayout()
        Me.GroupBox3.SuspendLayout()
        Me.GroupBox4.SuspendLayout()
        CType(Me.mskSSN, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.lblIncome, Me.Label1})
        Me.GroupBox1.Location = New System.Drawing.Point(16, 112)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(224, 72)
        Me.GroupBox1.TabIndex = 4
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "Previous Data"
        '
        'lblIncome
        '
        Me.lblIncome.BackColor = System.Drawing.Color.White
        Me.lblIncome.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblIncome.Location = New System.Drawing.Point(128, 32)
        Me.lblIncome.Name = "lblIncome"
        Me.lblIncome.Size = New System.Drawing.Size(80, 23)
        Me.lblIncome.TabIndex = 1
        Me.lblIncome.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(24, 32)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(88, 23)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "Preivous Income"
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'GroupBox2
        '
        Me.GroupBox2.Controls.AddRange(New System.Windows.Forms.Control() {Me.txtCurrentIncome, Me.Label6})
        Me.GroupBox2.Location = New System.Drawing.Point(16, 192)
        Me.GroupBox2.Name = "GroupBox2"
        Me.GroupBox2.Size = New System.Drawing.Size(224, 72)
        Me.GroupBox2.TabIndex = 5
        Me.GroupBox2.TabStop = False
        Me.GroupBox2.Text = "Current Data"
        '
        'txtCurrentIncome
        '
        Me.txtCurrentIncome.Location = New System.Drawing.Point(120, 32)
        Me.txtCurrentIncome.Name = "txtCurrentIncome"
        Me.txtCurrentIncome.Size = New System.Drawing.Size(88, 20)
        Me.txtCurrentIncome.TabIndex = 1
        Me.txtCurrentIncome.Text = ""
        '
        'Label6
        '
        Me.Label6.Location = New System.Drawing.Point(24, 32)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(88, 23)
        Me.Label6.TabIndex = 0
        Me.Label6.Text = "Current Income"
        Me.Label6.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'GroupBox3
        '
        Me.GroupBox3.Controls.AddRange(New System.Windows.Forms.Control() {Me.lblPrevIncome, Me.Label9, Me.lblCurrentIncome, Me.Label7, Me.lblPrevWithholdings, Me.Label4, Me.lblCurrentWithholdings, Me.Label2})
        Me.GroupBox3.Location = New System.Drawing.Point(256, 112)
        Me.GroupBox3.Name = "GroupBox3"
        Me.GroupBox3.Size = New System.Drawing.Size(224, 152)
        Me.GroupBox3.TabIndex = 6
        Me.GroupBox3.TabStop = False
        Me.GroupBox3.Text = "Total Amount"
        '
        'lblPrevIncome
        '
        Me.lblPrevIncome.BackColor = System.Drawing.Color.White
        Me.lblPrevIncome.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblPrevIncome.Location = New System.Drawing.Point(128, 24)
        Me.lblPrevIncome.Name = "lblPrevIncome"
        Me.lblPrevIncome.Size = New System.Drawing.Size(80, 23)
        Me.lblPrevIncome.TabIndex = 1
        Me.lblPrevIncome.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'Label9
        '
        Me.Label9.Location = New System.Drawing.Point(16, 24)
        Me.Label9.Name = "Label9"
        Me.Label9.Size = New System.Drawing.Size(112, 23)
        Me.Label9.TabIndex = 0
        Me.Label9.Text = "Previous Income"
        Me.Label9.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'lblCurrentIncome
        '
        Me.lblCurrentIncome.BackColor = System.Drawing.Color.White
        Me.lblCurrentIncome.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblCurrentIncome.Location = New System.Drawing.Point(128, 88)
        Me.lblCurrentIncome.Name = "lblCurrentIncome"
        Me.lblCurrentIncome.Size = New System.Drawing.Size(80, 23)
        Me.lblCurrentIncome.TabIndex = 5
        Me.lblCurrentIncome.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'Label7
        '
        Me.Label7.Location = New System.Drawing.Point(16, 88)
        Me.Label7.Name = "Label7"
        Me.Label7.Size = New System.Drawing.Size(112, 23)
        Me.Label7.TabIndex = 4
        Me.Label7.Text = "Current Income"
        Me.Label7.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'lblPrevWithholdings
        '
        Me.lblPrevWithholdings.BackColor = System.Drawing.Color.White
        Me.lblPrevWithholdings.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblPrevWithholdings.Location = New System.Drawing.Point(128, 56)
        Me.lblPrevWithholdings.Name = "lblPrevWithholdings"
        Me.lblPrevWithholdings.Size = New System.Drawing.Size(80, 23)
        Me.lblPrevWithholdings.TabIndex = 3
        Me.lblPrevWithholdings.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(8, 56)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(120, 23)
        Me.Label4.TabIndex = 2
        Me.Label4.Text = "Previous Withholdings"
        Me.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'lblCurrentWithholdings
        '
        Me.lblCurrentWithholdings.BackColor = System.Drawing.Color.White
        Me.lblCurrentWithholdings.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblCurrentWithholdings.Location = New System.Drawing.Point(128, 120)
        Me.lblCurrentWithholdings.Name = "lblCurrentWithholdings"
        Me.lblCurrentWithholdings.Size = New System.Drawing.Size(80, 23)
        Me.lblCurrentWithholdings.TabIndex = 7
        Me.lblCurrentWithholdings.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(16, 120)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(112, 23)
        Me.Label2.TabIndex = 6
        Me.Label2.Text = "Current Withholdings"
        Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'btnQuit
        '
        Me.btnQuit.Location = New System.Drawing.Point(336, 8)
        Me.btnQuit.Name = "btnQuit"
        Me.btnQuit.TabIndex = 7
        Me.btnQuit.Text = "Quit"
        '
        'btnCompute
        '
        Me.btnCompute.Location = New System.Drawing.Point(160, 8)
        Me.btnCompute.Name = "btnCompute"
        Me.btnCompute.TabIndex = 1
        Me.btnCompute.Text = "Compute"
        '
        'cdlSaveFile
        '
        Me.cdlSaveFile.FileName = "doc1"
        '
        'btnRead
        '
        Me.btnRead.Location = New System.Drawing.Point(72, 8)
        Me.btnRead.Name = "btnRead"
        Me.btnRead.TabIndex = 0
        Me.btnRead.Text = "Read"
        '
        'btnSave
        '
        Me.btnSave.Location = New System.Drawing.Point(248, 8)
        Me.btnSave.Name = "btnSave"
        Me.btnSave.TabIndex = 2
        Me.btnSave.Text = "Save"
        '
        'GroupBox4
        '
        Me.GroupBox4.Controls.AddRange(New System.Windows.Forms.Control() {Me.mskSSN, Me.Label5, Me.txtName, Me.Label3})
        Me.GroupBox4.Location = New System.Drawing.Point(16, 48)
        Me.GroupBox4.Name = "GroupBox4"
        Me.GroupBox4.Size = New System.Drawing.Size(464, 56)
        Me.GroupBox4.TabIndex = 3
        Me.GroupBox4.TabStop = False
        '
        'mskSSN
        '
        Me.mskSSN.ContainingControl = Me
        Me.mskSSN.Location = New System.Drawing.Point(368, 24)
        Me.mskSSN.Name = "mskSSN"
        Me.mskSSN.OcxState = CType(resources.GetObject("mskSSN.OcxState"), System.Windows.Forms.AxHost.State)
        Me.mskSSN.TabIndex = 3
        '
        'Label5
        '
        Me.Label5.Location = New System.Drawing.Point(280, 24)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(80, 23)
        Me.Label5.TabIndex = 2
        Me.Label5.Text = "SSN"
        Me.Label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'txtName
        '
        Me.txtName.Location = New System.Drawing.Point(104, 24)
        Me.txtName.Name = "txtName"
        Me.txtName.TabIndex = 1
        Me.txtName.Text = ""
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(16, 24)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(80, 23)
        Me.Label3.TabIndex = 0
        Me.Label3.Text = "Name"
        Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(496, 286)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.GroupBox4, Me.btnSave, Me.btnRead, Me.btnCompute, Me.btnQuit, Me.GroupBox3, Me.GroupBox2, Me.GroupBox1})
        Me.Name = "Form1"
        Me.Text = "6-34 Computing the FICA Withholding"
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox2.ResumeLayout(False)
        Me.GroupBox3.ResumeLayout(False)
        Me.GroupBox4.ResumeLayout(False)
        CType(Me.mskSSN, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuit.Click
        Me.Close()
    End Sub

    Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCompute.Click
        CalculateWH()
    End Sub

    Sub ClearScreen()
        Dim Temp As String
        Temp = mskSSN.Mask
        mskSSN.Mask = ""
        mskSSN.CtlText = ""
        mskSSN.Mask = Temp
        txtName.Text = ""
        lblIncome.Text = ""
        txtCurrentIncome.Text = ""
        lblPrevIncome.Text = ""
        lblPrevWithholdings.Text = ""
        lblCurrentIncome.Text = ""
        lblCurrentWithholdings.Text = ""
    End Sub

    Sub CalculateWH()
        Dim CurrentIncome As Double
        Dim PrevIncome As Double
        Dim CurrentWithholding As Double
        Dim TotalWithholding As Double
        Dim PrevWithholding As Double
        Dim TotalIncome As Double

        CurrentIncome = Val(txtCurrentIncome.Text)
        If IsNumeric(lblPrevIncome.Text) Then
            PrevIncome = CDbl(lblPrevIncome.Text)
        End If
        TotalIncome = CurrentIncome + PrevIncome

        'Compute previous withholding
        'For SST
        If PrevIncome < 45000 Then
            PrevWithholding = (PrevIncome * 0.062)
        Else
            'Max SST
            PrevWithholding = 45000 * 0.062
        End If
        'For Meidicare tax
        If PrevIncome < 120000 Then
            PrevWithholding += (PrevIncome * 0.0145)
        Else
            'Max MT
            PrevWithholding += 120000 * 0.0145
        End If
        'Compute total withholding
        'for SST
        If TotalIncome < 45000 Then
            TotalWithholding = (TotalIncome * 0.062)
        Else
            TotalWithholding = (45000 * 0.062)
        End If
        'For MT
        If TotalIncome < 120000 Then
            TotalWithholding += (TotalIncome * 0.0145)
        Else
            TotalWithholding += 120000 * 0.0145
        End If
        CurrentWithholding = TotalWithholding - PrevWithholding

        lblPrevIncome.Text = Format(PrevIncome, "Standard")
        lblCurrentIncome.Text = Format(CurrentIncome, "Standard")
        lblPrevWithholdings.Text = Format(PrevWithholding, "Standard")
        lblCurrentWithholdings.Text = Format(CurrentWithholding, "Standard")
    End Sub

    Private Function GetTheFileName(ByVal TheDialog As FileDialog, ByVal TheTitle As String, ByVal TheFilter As String) As String
        With TheDialog
            .Title = TheTitle
            .Filter = TheFilter
            .ShowDialog()
            Return (.FileName)
        End With
    End Function

    Sub ReadPayrollData()
        Dim Response As Integer

        Dim PayData As String
        Dim P0, P As Integer
        Dim Temp As String

        If PayrollReader.Peek() = -1 Then
            MsgBox("No More Records")
            ClearScreen()
            Exit Sub
        End If
        PayData = PayrollReader.ReadLine()
        P = InStr(PayData, ",")
        Temp = mskSSN.Mask
        mskSSN.Mask = ""
        mskSSN.CtlText = Microsoft.VisualBasic.Left(PayData, P - 1)
        mskSSN.Mask = Temp
        P0 = P
        P = InStr(P + 1, PayData, ",")
        txtName.Text = Mid(PayData, P0 + 1, P - P0 - 1)
        P0 = P
        P = InStr(P + 1, PayData, ",")
        lblPrevIncome.Text = Format(CDbl(Mid(PayData, P0 + 1, P - P0 - 1)), "Standard")
        lblIncome.Text = lblPrevIncome.Text
        Temp = Mid(PayData, P + 2)
        If Missing(Temp) Then
            Temp = "0"
        End If
        lblPrevWithholdings.Text = Format(CDbl(Temp), "Standard")
    End Sub

    Sub SavePayrollData()
        Dim OutputLine As String
        Dim TotalIncome, totalWH As Double

        TotalIncome = CDbl(lblCurrentIncome.Text) + CDbl(lblPrevIncome.Text)
        totalWH = CDbl(lblPrevWithholdings.Text) + CDbl(lblCurrentWithholdings.Text)
        OutputLine = mskSSN.CtlText & ", " & txtName.Text & ", " & TotalIncome & ", " & totalWH
        PayrollWriter.WriteLine(OutputLine)
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim InFileName As String
        Dim OutFileName As String
        InFileName = GetTheFileName(cdlOpenFile, "Where is the payroll y-t-d file?", FileFilter)
        OutFileName = GetTheFileName(cdlSaveFile, "Specify filename to save", FileFilter)
        PayrollReader = New System.IO.StreamReader(InFileName)
        PayrollWriter = New System.IO.StreamWriter(OutFileName)
    End Sub

    Private Sub btnRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRead.Click
        ReadPayrollData()
    End Sub

    Function Missing(ByVal A As String) As Boolean
        Return (Len(Trim(A)) = 0)
    End Function

    Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
        If Missing(txtName.Text) OrElse Missing(mskSSN.ClipText) Then
            MsgBox("Please Enter a valid name and SSN")
            Exit Sub
        End If
        SavePayrollData()
        MsgBox("Record saved", MsgBoxStyle.Information)
        ClearScreen()
    End Sub

    Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        Dim SavedMore As Boolean
        Dim TheLine As String

        Do Until PayrollReader.Peek = -1
            TheLine = PayrollReader.ReadLine
            PayrollWriter.WriteLine(TheLine)
            SavedMore = True
        Loop
        If SavedMore Then
            MsgBox("Some previous payroll data were not processed but copied and saved in current file", MsgBoxStyle.Information)
        End If
        PayrollReader.Close()
        PayrollWriter.Close()
    End Sub
End Class

Download this snippet    Add to My Saved Code

reading and writing and computing payroll data for school project Comments

No comments have been posted about reading and writing and computing payroll data for school project. Why not be the first to post a comment about reading and writing and computing payroll data for school project.

Post your comment

Subject:
Message:
0/1000 characters