Hi all, I am new to this VB programming stuff, so far so good, but this last project of the semester has me wanting to pull out my hair, and the textbook is more aggrevating.

I am wanting to pull info, that is typed in a inputbox, and put it in a listbox

sounds simple enough. BUT...

I have a input box that asks for the # of Employees to figure payroll for, and then after you type in the number ,the program proceeds to ask the hourly wage, pay, and all 3 forms of taxes to take out. This all works, the problem... I cant figure how do I take each employee and list each of their pieces of information in a single line per employee

example:

employee# HoursWorked HourlyPay State tax Federal Tax FICA tax NetPay
1 10 10.50 3% 12% 2% $$
2 20 15.25 3% 15% 2.5% $$

thats what I want my listbox to look like, all I can get it to insert is the number 10 if I use the last line of code

ANY SUGGESTIONS are welcome, and appreciated!!

this is what I have that actually works (except for the last line before end sub'........)

Public Class Form1

'Angela
'This program will allow you to figure payroll for employees

Dim strEmployee
Dim intNumEmployees
Dim sngTotal
Dim intCount
Dim strHoursWorked
Dim strHourlyPay
Dim strPercentState
Dim strPercentFederal
Dim strPercentFICA


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

Private Sub btClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
lstPayroll.Items.Clear()

End Sub

Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click

'This gets the # of employees to figure payroll for
strEmployee = InputBox("How many Employees to figure payroll for? ", "Enter a Value")
intNumEmployees = CInt(strEmployee)
intCount = 0

'Gets the employees information.
Do Until intCount >= intNumEmployees
intCount += 1
strHoursWorked = InputBox("Enter the # of Hours Worked by Employee " & intCount, "Hours Worked")
strHourlyPay = InputBox("Enter the Hourly Amount paid to Employee " & intCount, "Hours Pay")
strPercentState = InputBox("Enter the Percent State Tax to take out " & intCount, "State Percent Withheld")
strPercentFederal = InputBox("Enter the Percent Federal Tax to take out " & intCount, "Federal Percent Withheld")
strPercentFICA = InputBox("Enter the Percent FICA Tax to take out " & intCount, "Fica Percent Withheld")
Loop

lstPayroll.Items.Add(strHoursWorked)

End Sub
End Class

Hi

I think you want to use a ListView instead of a ListBox. With a ListView you can have multiple columns (like windows explorer details view). You must remember to set the View property to List or Details and the very first item you add you must use the Items methods (in your case you would use Items.Add(employeeID)) and then the Items(x).SubItems(...) method to add values to the extra columns

Hope this helps

Kev

Hello,

First of all THANK YOU for your help ;)

for some crazy reason the assignment calls for a listbox (go figure), I have been working on this forever! but I have added since I posted. This actually will list all the info in a straight across the listbox, BUT it concantenate and copies line 1 and adds line 2 so I have both employee 1 & employee2 2 on line 2?? is there a way to concantenate the info and then after it skips to anking about wmployee 2 to clear the value, yet keep it on the listbox??

This is what I changed from the bottom of the original:

Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click

'This gets the # of employees to figure payroll for
strEmployee = InputBox("How many Employees to figure payroll for? ", "Enter a Value")
intNumEmployees = CInt(strEmployee)
intCount = 0

'Gets the employees # of worked hours.
For intCount = 0 To intNumEmployees
intCount += 1
strHoursWorked = InputBox("Enter the # of Hours Worked by Employee " & intCount, "Hours Worked")

strHourlyPay = InputBox("Enter the Hourly Amount paid to Employee " & intCount, "Hours Pay")

strPercentState = InputBox("Enter the Percent State Tax to take out " & intCount, "State Percent Withheld")

strPercentFederal = InputBox("Enter the Percent Federal Tax to take out " & intCount, "Federal Percent Withheld")

strPercentFICA = InputBox("Enter the Percent FICA Tax to take out " & intCount, "Fica Percent Withheld")

strOut += ("Employee " & intCount)
strOut += (" " & strHoursWorked & "=")
strOut += (" " & strHourlyPay & "=")
strOut += ("Hourly Pay ")
strOut += (" " & strPercentState & "=")
strOut += ("Percent State Tax")
strOut += (" " & strPercentFederal & "=")
strOut += ("Percent Federal Tax")
strOut += (" " & strPercentFICA & "=")
strOut += ("Percent FICA Tax")

lstPayroll.Items.Add(strOut)
Next intCount


End Sub

Hi

Ah, i think you need to reset the strOut variable at the start of your "for" loop otherwise it will still contain the values from the previous loop iteration.

Think a simple strOut = "" will solve your problem

Hope this helps

Kev

I have to go back and format some of my #'s but...

That SO worked........ Thank U :twisted: Thank U

take care

Angela

Excellent, glad to hear it.

Just one final tip, normally when you do a for loop you would increment the index just before the loop iterates. So for example in your case you would have

For intCount = 1 To intNumEmployees
......
intCount += 1
Next

So rather than starting the intCount at 0 and incrementing it straight away, start it at 1 then increment right at the end.

Hope this makes some sense... ;)

Kev

WOO WHOO

finally got that to work, Thanks to U

I still have a couple things to tweek.

Thanks again

c-ya next time I get stuck!

Angela :icon_lol:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.