thankins Posted October 7, 2003 Posted October 7, 2003 Good evening everyone! I have a few questions...ok 3 questions to ask. Here is a little background about the program i am working on: I need to create an application that calculates and displays payroll for 4 employees. It accepts the following data from the user. 1) Num of hours worked. 2.) Hourly Rate. 3)Precent withheld for Fica. 4)Precent for federal. 5.Percent for State. It then must NOT allow the user to enter anymore data after the 4 employees have been entered! So after all that here is my code for the calc_click method, and few Sub and Functions that I created to impress those who looked at the program. Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click 'Declares local variables for btnCalculate_Click Method Dim empName As String Dim hrRate, hrsWorked As Single Dim stateTax, fedTax As Single Dim totalPay, grossPay, ficaTax As Single 'Gets data,compute payroll,display results Call InputData(empName, hrRate, hrsWorked, fedTax) grossPay = Gross_Pay(hrRate, hrsWorked) ficaTax = Fica_Tax(grossPay, ficaTax) fedTax = Fed_Tax(grosspay, fedTax) stateTax = State_Tax(grosspay, stateTax) totalPay = CSng(Total_Pay(grossPay, ficaTax, fedTax, stateTax)) Call ShowPayroll(empName, grosspay, totalPay, ficaTax, fedTax, stateTax) End Sub Sub InputData(ByRef empName As String, ByRef hrRate As Single, ByRef hrsWorked As Single, ByRef fedTax As Single) ' Enter above two lines as one ' Get payroll data for employee empName = txtName.Text hrRate = CInt(Val(txtRate.Text)) hrsWorked = CInt(Val(txtHours.Text)) fedTax = CInt(Val(txtFederal.Text)) End Sub Sub ShowPayroll(ByRef empName As String, ByRef pay As Single, ByRef totalPay As Single, ByRef ficaTax As Single, ByRef fedTax As Single, ByVal stateTax As Single) ' Payroll output for listbox ' Payroll output for listbox lstOutput.Items.Add("Payroll results for ", & empName) lstOutput.Items.Add(" Gross pay this period:", FormatCurrency(pay) lstOutput.Items.Add(" Fica Taxes this period:", FormatCurrency(ficaTax) lstOutput.Items.Add(" Federal Income tax withheld:", FormatCurrency(fedTax) lstOutput.Items.Add(" State Income tax withheld:", FormatCurrency(stateTax) lstOutput.Items.Add("Net pay:", FormatCurrency(totalpay) End Sub Private Function Gross_Pay(ByRef hrWage As Single, ByRef hrsWorked As Single) As Single ' Compute weekly pay before taxes If hrsWorked <= 40 Then Gross_Pay = hrsWorked * hrWage Else Gross_Pay = CSng(40 * hrWage + (hrsWorked - 40) * 1.5 * hrWage) End If End Function Function Total_Pay(ByRef grossPay As Single, ByRef ficaTax As Single, ByRef fedTax As Single, ByRef stateTax As Single) As String ' Compute amount of net pay Total_Pay = CStr(grossPay - ficaTax - fedTax - stateTax) End Function Function Fed_Tax(ByRef grossPay As Single, ByRef fedTax As Single) As Single 'Compute amount to be taken for Federal Tax fedTax = grossPay * fedTax End Function Function Fica_Tax(ByRef grossPay As Single, ByRef ficaTax As Single) As Single ''Compute amount to be taken for FICA Tax ficaTax = grossPay * ficaTax End Function Function State_Tax(ByRef grossPay As Single, ByRef stateTax As Single) As Single 'Compute amount to be taken for State Tax stateTax = grossPay * stateTax End Function My problem is in the listoutput I recieve numerous errors that says " Too many arguments to 'Public Overloads Function Add(item As Object) As Integer'." I would like it to say which item added is in the output (i.e. Fica = 15.00, Gross Pay:15.00...etc) My second problem is that for some reason it isnt displaying correctly. I can get some of it to display such as Gross Pay but all the rest are zeros. Any idea! And finally my third problem is How do I stop the user from entering more then 4 employees like the instructions say? Thank you for your help! :D Travis :D :D Quote
thankins Posted October 7, 2003 Author Posted October 7, 2003 sorry I really didnt describe my first error that well, I get them here (the underline parts) lstOutput.Items.Add("Payroll results for ", & empName) and the following outputs! Quote
*Experts* Nerseus Posted October 7, 2003 *Experts* Posted October 7, 2003 First, change the line to (I removed the comma): lstOutput.Items.Add("Payroll results for " & empName) In all the rest of your functions, you're not returning anything. For example, change the State Tax function to: Function State_Tax(ByRef grossPay As Single, ByRef stateTax As Single) As Single 'Compute amount to be taken for State Tax State_Tax = grossPay * stateTax End Function You return a value by setting the function name (State_Tax in this case) to a value. You DID do that Gross_Pay which is why it's working. What does your UI look like? Are you using DataSets? To help you limit them to 4 employees, I need more info on how you're storing the 4 you've got. (Grid entry, textboxes, etc.) -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
thankins Posted October 8, 2003 Author Posted October 8, 2003 hnn I dont really know what you mean by UI, I am just storing the employees name in the list box and then want it to clear the form and allow the user to add another name. I was thinking about using a do while loop but really didnt know how to put it in, everytime i did it would allow me to enter one name and then it would just add that one name 4 times!!! 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.