Results 1 to 5 of 5

Thread: menu button perform click

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2007
    Posts
    25

    menu button perform click

    I am learning to create menu buttons and use the perform click. When I began by using the about in my code it works fine. However, when I try to do a perform click wiht my exit button in the menu strip it does not do anything...

    Code:
    Public Class Form1
    
        'Module level variables - These are private because they do 
        'Const for Retirement
        Const RETIREMENT_STANDARD As Decimal = 0.05D
        Const RETIREMENT_401A As Decimal = 0.08D
        Private retirementRateDecimal As Decimal
    
    
    
        Private Sub computeButton_Click(sender As Object, e As EventArgs) Handles computeButton.Click
            Try
                'CONST VARIABLES NEVER CHANGE ----- REMEMBER THIS!!!!!!!!!!!!!!!!!!!!!!
                'Const for Insurance - These are not module level variables because the results can change after being added together
                Const MEDICAL_INSURANCE As Decimal = 35.75D
                Const LIFE_INSURANCE As Decimal = 18.35D
                Const DENTAL_INSURANCE As Decimal = 4D
    
                'Const for Federal Tax Rate decimals
                Const TAX_08_LEVEL As Decimal = 0.08D
                Const TAX_18_LEVEL As Decimal = 0.18D
                Const TAX_28_LEVEL As Decimal = 0.28D
                Const TAX_08_PERCENT As Decimal = 985D
                Const TAX_18_PERCENT As Decimal = 2450D
    
                'Declare variables
                Dim hoursDecimal, payRateDecimal, grossPayDecimal, benefitsDecimal, netPayDecimal, federalTaxDecimal As Decimal
    
                'Make sure textboxes are valid
                If nameTextBox.Text.Trim = String.Empty Then
                    MessageBox.Show("Name is required", "Name Missing Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                    nameTextBox.Focus()
                    nameTextBox.SelectAll()
                ElseIf employeeIDMaskedTextBox.MaskCompleted = False Then
                    MessageBox.Show("Employee ID is not complete", "Employee ID Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                    employeeIDMaskedTextBox.Focus()
                    employeeIDMaskedTextBox.SelectAll()
                ElseIf departmentTextBox.Text.Trim = String.Empty Then
                    MessageBox.Show("Department is required", "Department Missing Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                    departmentTextBox.Focus()
                    departmentTextBox.SelectAll()
    
                    'This means if the result in this textbox is not a number or is less than 0 or greater than 60 to return an error
                ElseIf IsNumeric(hoursWorkedTextBox.Text) = False Or Decimal.Parse(hoursWorkedTextBox.Text,
                Globalization.NumberStyles.Number) <= 0D Or Decimal.Parse(hoursWorkedTextBox.Text, Globalization.NumberStyles.Number) > 60D Then
                    MessageBox.Show("Hours worked must be a number between 0 and 60", "Hours Value Error", MessageBoxButtons.OK,
                    MessageBoxIcon.Error)
                    hoursWorkedTextBox.Focus()
                    hoursWorkedTextBox.SelectAll()
                    'This means is the result in this textbox is not a number or less than 0 to return an error
                ElseIf IsNumeric(payRateTextBox.Text) = False Or Decimal.Parse(payRateTextBox.Text, Globalization.NumberStyles.Currency) <= 0D Then
                    MessageBox.Show("Pay rate worked must be a number greater than zero", "Pay Rate Value Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                    payRateTextBox.Focus()
                    payRateTextBox.SelectAll()
    
                Else
                    'Data rules are valid - Parse the textboxes
                    hoursDecimal = Decimal.Parse(hoursWorkedTextBox.Text, Globalization.NumberStyles.Number)
                    payRateDecimal = Decimal.Parse(payRateTextBox.Text, Globalization.NumberStyles.Currency)
    
                    'Compute gross pay
                    If hoursDecimal <= 40D Then
                        grossPayDecimal = Decimal.Round(hoursDecimal * payRateDecimal, 2)
                    Else
                        grossPayDecimal = Decimal.Round((40D * payRateDecimal) + ((hoursDecimal - 40D) * payRateDecimal * 1.5D), 2)
                    End If
    
                    'Compute insurance benefit deduction
                    If medicalInsuranceCheckBox.Checked Then
                        benefitsDecimal += MEDICAL_INSURANCE
                    End If
                    If lifeInsuranceCheckBox.Checked Then
                        benefitsDecimal += LIFE_INSURANCE
                    End If
                    If dentalInsuranceCheckBox.Checked Then
                        benefitsDecimal += DENTAL_INSURANCE
                    End If
    
                    'Compute the federal tax
                    'Use this when a single variable, single expression, single control property, or similiar object
                    'is to be evaluated and different actions are taken depending on the value of the expression
                    'Advantage is it is easier to read than multiple if statements
                    Select Case grossPayDecimal
                        Case Is <= TAX_08_PERCENT
                            federalTaxDecimal = Decimal.Round(TAX_08_LEVEL * grossPayDecimal, 2)
                        Case Is <= TAX_18_PERCENT
                            federalTaxDecimal = Decimal.Round(grossPayDecimal * TAX_18_LEVEL, 2)
                        Case Else
                            federalTaxDecimal = Decimal.Round(grossPayDecimal * TAX_28_LEVEL, 2)
                    End Select
    
                    'Use the retirement rate set in the checked changed event for the retirement radio button controls
                    benefitsDecimal += Decimal.Round(grossPayDecimal * retirementRateDecimal, 2)
    
                    'Compute the net pay
                    netPayDecimal = grossPayDecimal - federalTaxDecimal - benefitsDecimal
    
                    'Display output
                    payRateTextBox.Text = payRateDecimal.ToString("C")
                    grossPayTextBox.Text = grossPayDecimal.ToString("C")
                    netPayTextBox.Text = netPayDecimal.ToString("C")
                    federalTaxTextBox.Text = federalTaxDecimal.ToString("N")
                    benefitsTextBox.Text = benefitsDecimal.ToString("N")
    
                End If
            Catch ex As Exception
                MessageBox.Show("Unexpected error: " & ControlChars.NewLine & ex.Message, "Compute Button Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
    
        End Sub
    
    
    
        Private Sub exitButton_Click(sender As Object, e As EventArgs) Handles exitButton.Click
            'Close the form if the system user responds yes
            Dim messageString As String = "Do you want to close the form?"
            Dim buttonDialogResult As DialogResult = MessageBox.Show(messageString, "Quit?", MessageBoxButtons.YesNo, MessageBoxIcon.Question,
            MessageBoxDefaultButton.Button2)
            If buttonDialogResult = Windows.Forms.DialogResult.Yes Then
                Me.Close()
            End If
        End Sub
    
        Private Sub resetButton_Click(sender As Object, e As EventArgs) Handles resetButton.Click
            'Reset all textboxcontrol
            nameTextBox.Clear()
            employeeIDMaskedTextBox.Clear()
            departmentTextBox.Clear()
            hoursWorkedTextBox.Clear()
            payRateTextBox.Clear()
            grossPayTextBox.Clear()
            federalTaxTextBox.Clear()
            benefitsTextBox.Clear()
            netPayTextBox.Clear()
    
            'Reset retirement benefit status to none
            noRetirementPlanRadioButton.Checked = True
    
            'Uncheck benefits checkboxes
            medicalInsuranceCheckBox.Checked = False
            lifeInsuranceCheckBox.Checked = False
            dentalInsuranceCheckBox.Checked = False
    
            'Set focus to name textbox
            nameTextBox.Focus()
        End Sub
    
    
    
        Private Sub noneRetirementPlanRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles noRetirementPlanRadioButton.CheckedChanged,
            retirementStandardRadioButton.CheckedChanged, retirement401ARadioButton.CheckedChanged
            'Create a radio button in memory and store the values of sender to it
            Dim checkedRadioButton As RadioButton = CType(sender, RadioButton)
    
            'Use select case to evaluate the name of the radio button to decide which controls to enable/disable
            Select Case checkedRadioButton.Name
                Case "noRetirementRadioButton"
                    retirementRateDecimal = 0D
                Case "retirementStandardRadioButton"
                    retirementRateDecimal = RETIREMENT_STANDARD
                Case "retirement401ARadioButton"
                    retirementRateDecimal = RETIREMENT_401A
            End Select
        End Sub
    
        Private Sub FileToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles FileToolStripMenuItem.Click
    
        End Sub
    
        Private Sub AboutToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles AboutToolStripMenuItem.Click
            'Display the About Message box
            Dim messageString As String = "Programmed by Bryan Kruep" & ControlChars.NewLine & "Today's Date/Time:  " & Date.Now.ToString
            Dim titleString As String = "About the Payroll Application"
    
            'Display output message
            MessageBox.Show(messageString, titleString, MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Sub
    
    
        Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
            exitButton.PerformClick()
        End Sub
    End Class

  2. #2
    Junior Member
    Join Date
    Sep 2012
    Posts
    18

    Re: menu button perform click

    You haven't told the exit button to show the message box... i think.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Nov 2007
    Posts
    25

    Re: menu button perform click

    I tried me.close() and it also does not do anything

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: menu button perform click

    Well the code works perfectly with any control I launch it from so I'm left wondering whether you mean toolstrip which could hold a button or, as you said, menustrip which could not? If this is indeed a button then there is is absolutely no reason why this should fail as far as I can see. Which version of VS are you using? If it's an older one then I suppose it might have a problem with MessageBox.Show in which case substitute MessageBox.ShowDialog.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  5. #5
    Fanatic Member
    Join Date
    Oct 2011
    Location
    Sydney, Australia
    Posts
    756

    Re: menu button perform click

    hmm maybe the button your pressing isnt called exitButton ? when you double click it in designer it goes to this code? if so try comment it all off and write

    Code:
    msgbox("testing")
    if that works then its the right button and something is wrong with your code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width