title: VB Payroll Calculator ( For..Next Loop help please?)
body: <p>I am trying to figure out why my For...Next loop will not execute properly in this program. It was supposed to allow the user to input payroll information for 4 different employees; however, it just copies the user input for the first employee 4 times in the listbox. I entered the code as I understand it from <a href="http://msdn.microsoft.com/en-us/library/zxkf5z4b%28v=vs.71%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/zxkf5z4b%28v=vs.71%29.aspx</a> so I am not sure what I am doing wrong. I've tried changing the loop counter from 0 to 1 but that did not resolve the error.</p>
  
  <pre><code>    Public Class Payroll
  
  Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
     Me.Close()          'Exit application.
  End Sub
  
  Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
  txtHoursWorked.Clear()
  txtHourlyPayRate.Clear()
  txtStateTaxRate.Clear()     ' Clear textboxes and set focus to txtHoursWorked.
  txtFedTaxRate.Clear()
  txtFICA.Clear()
  
  txtHoursWorked.Focus()
  End Sub
  
  Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
  Dim intCount As Integer = 0   ' Loop Counter.
  Dim intGrossPay As Integer  ' To hold gross pay.
  Dim intStateTax As Integer  ' To hold state tax withholding.
  Dim intFedTax As Integer    ' To hold fed tax withholding.
  Dim intFICA As Integer      ' To hold FICA withholding.
  Dim intNetPay As Integer    ' To hold net pay.
  Dim strPay As String        ' To hold output.
  
  For intCount = 1 To 4 Step 1
  'Calculate gross pay.
  intGrossPay = txtHourlyPayRate.Text * txtHoursWorked.Text
  
  'Calculate state income tax withholding.
  intStateTax = intGrossPay * txtStateTaxRate.Text
  
  'Calculate fed tax withholding.
  intFedTax = intGrossPay * txtFedTaxRate.Text
  
  ' Calculate FICA witholding.
  intFICA = intGrossPay * txtFICA.Text
  
  'Calculate net pay.
  intNetPay = intGrossPay - (intStateTax + intFedTax + intFICA)
  
  If (intStateTax + intFedTax + intFICA) &lt; intGrossPay Then
      ' Create a string to display.
      strPay = ("Employee number" &amp; (intCount.ToString) &amp; ": " &amp; "Gross pay is " &amp; (intGrossPay.ToString("C")) &amp; ". " &amp;
          "State tax withholding is " &amp; (intStateTax.ToString("C")) &amp; ". " &amp; "Federal tax withholding is " &amp; (intFedTax.ToString("C")) &amp;
          ". " &amp; "FICA withholdings is " &amp; (intFICA.ToString("C")) &amp; ". " &amp; "Net pay is " &amp; (intNetPay.ToString("C")) &amp; ". ")
  
      ' Add string to listbox."
      lstEmployeePay.Items.Add(strPay)
  
  ElseIf (intStateTax + intFedTax + intFICA) &gt; intGrossPay Then
      MessageBox.Show("Error: Withholdings are too much.")
  
  End If
  Next
  End Sub
  End Class
  </code></pre>