Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I need help. Here is my problem I need an if statement that would stop the user from entering more data into the textboxes after they enter the data 4 times. I dont know how to do it as of now.

 

Here is my code.

 

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

   End Sub

   Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
       txtState.Text = " "
       txtFederal.Text = " "
       txtFica.Text = " "
       txtHours.Text = " "
       txtRate.Text = " "
       txtName.Text = " "
       lstOutput.Items.Clear()
       txtName.Focus()

   End Sub

   Private Sub txtHours_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtHours.Validating
       'Vaildates that a number has been entered into the text box

       If Not IsNumeric(txtHours.Text) Then
           MessageBox.Show("Hours worked must be a number.", "Invaild Input", MessageBoxButtons.OK, _
           MessageBoxIcon.Error)

           'Select the existing text in the text box.
           txtHours.SelectionStart = 0
           txtHours.SelectionLength = txtHours.Text.Length
           'Set the e.Cacel to true so the focus will stay in the control
           e.Cancel = True
       Else
           e.Cancel = False
       End If
   End Sub


   Private Sub txtRate_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtRate.Validating
       'Vaildates that a number has been entered into the text box

       If Not IsNumeric(txtRate.Text) Then
           MessageBox.Show("Pay Rate must be a number.", "Invaild Input", MessageBoxButtons.OK, _
           MessageBoxIcon.Error)

           'Select the existing text in the text box.
           txtRate.SelectionStart = 0
           txtRate.SelectionLength = txtRate.Text.Length
           'Set the e.Cacel to true so the focus will stay in the control
           e.Cancel = True
       Else
           e.Cancel = False
       End If
   End Sub

   Private Sub txtState_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtState.Validating
       'Vaildates that a number has been entered into the text box

       If Not IsNumeric(txtState.Text) Then
           MessageBox.Show("State taxes must be a number.", "Invaild Input", MessageBoxButtons.OK, _
           MessageBoxIcon.Error)

           'Select the existing text in the text box.
           txtState.SelectionStart = 0
           txtState.SelectionLength = txtState.Text.Length
           'Set the e.Cacel to true so the focus will stay in the control
           e.Cancel = True
       Else
           e.Cancel = False
       End If
   End Sub

   Private Sub txtFederal_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtFederal.Validating
       'Vaildates that a number has been entered into the text box

       If Not IsNumeric(txtFederal.Text) Then
           MessageBox.Show("Federal taxes must be a number.", "Invaild Input", MessageBoxButtons.OK, _
           MessageBoxIcon.Error)

           'Select the existing text in the text box.
           txtFederal.SelectionStart = 0
           txtFederal.SelectionLength = txtFederal.Text.Length
           'Set the e.Cacel to true so the focus will stay in the control
           e.Cancel = True
       Else
           e.Cancel = False
       End If
   End Sub

   Private Sub txtFica_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtFica.Validating
       'Vaildates that a number has been entered into the text box

       If Not IsNumeric(txtFica.Text) Then
           MessageBox.Show("F.I.C.A. withholdings must be a number.", "Invaild Input", MessageBoxButtons.OK, _
           MessageBoxIcon.Error)

           'Select the existing text in the text box.
           txtFica.SelectionStart = 0
           txtFica.SelectionLength = txtFica.Text.Length
           'Set the e.Cacel to true so the focus will stay in the control
           e.Cancel = True
       Else
           e.Cancel = False
       End If
   End Sub

   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, ficaTax, stateTax)
       grossPay = Gross_Pay(hrRate, hrsWorked)
       fedTax = Fed_Tax(grossPay, fedTax)
       ficaTax = Fica_Tax(grossPay, ficaTax)
       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, ByRef ficaTax As Single, ByRef stateTax As Single)

       ' Get payroll data for employee
       empName = txtName.Text
       hrRate = CInt(txtRate.Text)
       hrsWorked = CInt(txtHours.Text)
       fedTax = CSng(txtFederal.Text)
       ficaTax = CSng(txtFica.Text)
       stateTax = CSng(txtState.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
       
       lstOutput.Items.Add("Payroll results for " + (empName))
       lstOutput.Items.Add("     Gross pay this period:" + FormatCurrency(pay))
       lstOutput.Items.Add("     F.I.C.A. tax withheld:" + 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

   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
       Fed_Tax = 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
       Fica_Tax = 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
       State_Tax = grossPay * stateTax

   End Function

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

   End Sub
End Class

 

Thank you for your help!

Posted

yea

 

Sorry i didnt explain it better

 

This is a payroll program that will caluclate Gross Pay, and taxes (Fica Federal and state) the user will enter a name and enter the total hours worked, payrate, and the percent of taxes for each tax. and then it will display the gross pay and etc in a listbox.

I need to limit it so that the user can only enter 4 employess into the textboxes.

 

I thought and if statement like this would work

 


Dim count as short

Do count while < 4



count+=1

if count = 4

'disable all the boxes and fire message; messagebox.show("You have reached the maximum for employees allowed to be entered", "Maximum Reached") 

 

I just didnt know where to put it

  • *Experts*
Posted

Well, where-ever you are "committing" the data (like, a Save button or something), increment a form-wide counter. Something like this:

 

'Form-wide:
Dim count As Integer

'In the Save button or whatever
If count < 4 Then
 'process the employee
 count += 1
Else
 MessageBox.Show("You may only enter 4 employees")
End If

  • 4 weeks later...
Posted

well, yes but you should put a better ending to ur program , instead of using End, this can cause memory leaks!!!!!

 

try to use

 


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


   End Sub

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...