locked
Commission Calculator RRS feed

  • Question

  • Hi guys,

    i was going to design a form that calculates the the commission by the given sales value and it worked appart fom one thing which is the summery button whch i wonted it to display the highest commission paid including the highest name after compairing the commission values but am stuck on this one and hope i'll find some one to help me on this one here is the code anyway . thx

     

    'Author:Alemayehu  
    Option Explicit On  
    Option Strict On  
    Public Class Form1  
        Const LIMIT As Integer = 15000 
        Const LOWER_COMMISSION_RATE As Double = 0.05  
        Const HIGHER_COMMISSION_RATE As Double = 0.09  
        Const STANDARD_COMMISSION As Double = LIMIT * LOWER_COMMISSION_RATE  
        Private HigherName As String 'declare a variable called Hname  
        Private HigherSale As Double 'declare a variable called Hsale  
        Private TotalCommision As Double  
        Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click  
            Me.Close() 'it will close the form  
        End Sub  
     
     
        Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click  
            Dim dSale As Double 'declare a variable called dSale  
            Dim dCommission As Double  
            Dim sName As String 'declare a variable called sname  
            Dim bigCommission As Double  
            Dim smallcommision As Double  
            Dim savecommission As Double  
            sName = txtName.Text 'it will assign the value entered on sName  
     
     
            If txtName.Text = "" Then 'if user enter nothing on the name field it will display messege box  
                MessageBox.Show("please enter the Name", "error", MessageBoxButtons.OK, MessageBoxIcon.Question)  
                txtName.Focus()  'cursor on the name field  
                Exit Sub 'stopes the commision messege box from being displayed  
            ElseIf txtSale.Text = "" Then 'if user enter nothing on the Sales field it will display messege box  
                MessageBox.Show("please enter the sale value", "error", MessageBoxButtons.OK, MessageBoxIcon.Question) 'displays message when no values entered  
                txtSale.Focus() 'cursor on the sale fiels  
                Exit Sub 'stopes the commision messege box from being displayed  
            ElseIf Double.TryParse(txtSale.Text, dSale) = False Then ''if user enter text value on the Sales field it will display messege box  
                MessageBox.Show("You did not enter a number", "Warning", _  
                MessageBoxButtons.OK, MessageBoxIcon.Warning) 'displays messege when entered wrong Value on the field  
                txtSale.Focus()  'cursor on sales field  
                txtSale.SelectAll() 'select the text on sales field  
                Exit Sub 'stopes the commision messege box from being displayed  
            ElseIf cbodepartment.SelectedIndex = -1 Then  
                MessageBox.Show("Please select department from the list", "warning", MessageBoxButtons.OK, MessageBoxIcon.Warning) 'displays message if the department didn't selected  
                cbodepartment.Focus() 'focus will be on The department drop down box  
                Exit Sub 'stopes the commision messege box from being displayed  
            End If 'Ends the If statment here   
     
            If dSale <= LIMIT Then  
                dCommission = dSale * LOWER_COMMISSION_RATE  
                MessageBox.Show("Commision:" & dCommission, sName, MessageBoxButtons.OK) 'displays the commision on message box  
                'HigherName = LIMIT.ToString  
                HigherName = txtName.ToString  
                smallcommision = dCommission 
            Else  
                'dSmallercommision = 750 'the sales value 15000 calculated by 5% will be 750  
                dCommission = (dSale - LIMIT) * HIGHER_COMMISSION_RATE + STANDARD_COMMISSION 'if the sales value is greater than 15000 it will take away 15000 and multiply the rest by 9% and add 750 on to it to get the commision value for the number entered  
                MessageBox.Show("Commision:" & dCommission, sName, MessageBoxButtons.OK) 'displays the commision on message box  
                HigherName = txtName.ToString  
                bigCommission = dCommission 
            End If 'end the if statement here  
     
            txtName.Clear() 'clear the name field  
            txtSale.Clear() 'clear the sales field  
            txtName.Focus() 'cursor on the name field  
     
            cbodepartment.SelectedIndex = -1 'clear the department dropdown menu  
            cbodepartment.Enabled = False 
            btnSummery.Enabled = True 'enables the Summery button  
            savecommission = dCommission 
            If savecommission > savecommission Then  
                HigherSale = savecommission 
            End If  
            'HigherSale = HIGHER_COMMISSION_RATE 
            'HigherName = sName 
            'End If  
            TotalCommision += dCommission  
        End Sub  
     
        Private Sub btnSummery_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSummery.Click  
            MessageBox.Show("Total commision payed:" & TotalCommision.ToString & vbNewLine & "biggest payout was to" & HigherName & "with" & HigherSale.ToString, "summery", MessageBoxButtons.OK)  
        End Sub  
     
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load  
            cbodepartment.Items.Add("furnishing") 'Add item list on the drop down menu  
            cbodepartment.Items.Add("Lighting") 'Add item list on the drop down menu  
            cbodepartment.Items.Add("Tablewear") 'Add item list on the drop down menu  
            btnSummery.Enabled = False 'disables the summery button  
            cbodepartment.Enabled = False 'disable the department drop down menu  
        End Sub  
     
        Private Sub txtSale_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSale.TextChanged  
            Dim dsale As Double  
     
            If Double.TryParse(txtSale.Text, dSale) = False Then ''if user enter text value on the Sales field it will display messege box  
     
            ElseIf dsale < 1 Or dsale > 40000 Then ''if user enter text value on the Sales field it will display messege box  
                MessageBox.Show("please enter sales amount between:£ 1 & 40,000", "Warning", _  
                MessageBoxButtons.OK, MessageBoxIcon.Information) 'displays a warning message  
                btnSummery.Enabled = False 'disables the summery button  
                txtSale.Focus()  'cursor on sales field  
                txtSale.SelectAll() 'select the text on sales field  
            Else  
                btnSummery.Enabled = True 
                cbodepartment.Enabled = True 
            End If  
        End Sub  
     
    End Class  
     

     

    Tuesday, March 3, 2009 3:03 PM

All replies