Attention: PROnetworks has upgraded our forum from phpbb2 to phpbb3!!

Please head over to our new converted forum at: http://www.pronetworks.org/forums/

This old forum will remain 'read-only' until approximately February 2009. We look forward to seeing you at the new forum!
Author Message
Guest
PostPosted: Wed Oct 15, 2003 1:24 pm Reply with quote


 
 




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.

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!
 
Back to top
Weaver
PostPosted: Wed Oct 15, 2003 5:42 pm Reply with quote

PROfessional Member
 
 


Joined: 18 Jun 2002
Posts: 2587
Location: /home/weaver/
Posts of this kind are not going to get any attention. First off, I would suggest registering with the site. Second, the code you have posted is way too long. I am not a VisualBasic programmer but even if I was I would not sort through what you have posted. What methods have you tried to implement this loop? What have your errors been? Lastly, when posting code that is longer than, say 20 lines, try to use a service like www.nomorepasting.com and then link to your code.

If you want a post like this to get attention, please clarify and simplify the post.

Thanks.

-Weaver
 
Back to top
Injunfarian
PostPosted: Wed Oct 15, 2003 9:47 pm Reply with quote

PRO Level 3
 
 


Joined: 18 Jan 2003
Posts: 79
i don't really get the question.. like what you mean after entering it 4 times? after doing the validate function 4 times or what? well either way whereever the 4 times is into play just make a global variable and then incriment it in the function and once hit reaches 4 then disable the text fields

not hard.
If i knew exactly what triggered it i could do the if statement but i don't know what you want to trigger it with
 
Back to top
dynamic_scripter
PostPosted: Sun Mar 07, 2004 1:57 pm Reply with quote

PRO Level 2
 
 


Joined: 03 Mar 2004
Posts: 12
Location: UK
i'd do something along these lines ...
Code:
Private clickValue As Integer = 0 '/// place this above your subs.
'/// then...

    Private Sub Clear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Clear.Click
        '/// reset entry options for TextBox1
        Dim defaultLength As Integer = 32767 '/// standard maximum length of a textbox.
        TextBox1.MaxLength = defaultLength
        clickValue = 0
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        If clickValue < 4 AndAlso IsNumeric(TextBox1.Text) Then
            '/// carry out your additional code here...
            clickValue += 1
        ElseIf clickValue < 4 AndAlso Not IsNumeric(TextBox1.Text) Then
            MessageBox.Show("Only numbers allowed , 3 chances left!", Me.Name, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            TextBox1.Clear()
            clickValue += 1
        Else
            TextBox1.MaxLength = 0
            TextBox1.Clear()
            clickValue += 1
        End If
    End Sub
 
Back to top
carvalho32
PostPosted: Fri Jun 25, 2004 5:29 pm Reply with quote

PRO Level 3
 
 


Joined: 25 Jun 2004
Posts: 53
Location: Brazil
Next time, simply put the subs header, their names should be intuitive, so we get your problem more easily... Seems like you are about to paste the entire solution!

The objective is not to flame, in truth, just be more objective in terms of algorithm. Your form class should include a public var that gets increased/decreased when a form or button get a click.
 
Back to top
Back to top
Index >> Webmaster Domain & Code Room >> If Statement in VB .NEt

Page 1 of 1

 


Tired of the Ads? Registered users have 80% less adverts.