| | |
From InputBox to ListBox??
Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved |
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
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
•
•
Join Date: Mar 2008
Posts: 12
Reputation:
Solved Threads: 1
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
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
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
•
•
Join Date: Mar 2008
Posts: 12
Reputation:
Solved Threads: 1
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
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
![]() |
Similar Threads
- Need help displaying an item in a list by via name (VB.NET)
- Need Help With Problem please (Visual Basic 4 / 5 / 6)
- Need help generating a Grand Total (VB.NET)
- overwriting files. (Visual Basic 4 / 5 / 6)
- adding totals in listboxes (Visual Basic 4 / 5 / 6)
Other Threads in the VB.NET Forum
- Previous Thread: how do i telnet to an ip address from vb.net code
- Next Thread: how to read data from text file into data grid???
Views: 1787 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for VB.NET
.net .net2005 30minutes 2005 2008 access account application arithmetic array arrays basic binary bing button buttons c# center check code combobox component connectionstring convert crystalreport data database databasesearch datagrid datagridview design dissertation dissertations dissertationthesis dll dropdownlist excel file-dialog folder ftp google hardcopy highlighting image images inline insert listview login mobile ms net networking output passingparameters peertopeervideostreaming picturebox picturebox1 plugin port print printing problem problemwithinstallation project reports" save savedialog searchbox serial server soap sorting sql string syntax table tcp text textbox timer toolbox trim update updown usercontrol vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web wpf





