|
-
Oct 16th, 2006, 04:19 PM
#1
Thread Starter
New Member
Trying to write a function to calculate commission
Ok here is what I am doing. I have to develop a program that determines how much a salesperson makes. Here is the following instructions:
A salesperson earns a weekly base salary plus a commission when sales are at or above quota. Create a project that allows the user to input the weekly sales, and teh salesperson name, calculates the commission, and displays summary information.
Write a function procedure to calculate the commission. The function must compare sales to the quota. When the sales are equal to or greater than the quota, calculate the commission by multiplying sales by the commission rae. Each salesperons receives the base pay plus the commission (if one has been earned).
I am having trouble developing a function. I have most of the code for the calculate button coded. Here is what I have so far. When the calculate button is pushed it must output the commission(if one is earned), total sales adn the total pay earned.
VB Code:
'Program Name Chapter5ExtraCredit
'Programmer Chad R. Bruckman
'Date 10/15/2006
'Description A salesperson earns a weekly base salary
' plus a commission when sales weekly sales
' are at or above quota.
Public Class salesForm
'Declare module-level variables for summary information.
Dim totalCommissionDecimal, totalsalesDecimal, totalpayDecimal As Decimal
Dim salesCountInteger As Integer
'Declare constants
Const QUOTA_Decimal = 1000
Const COMMISSION_RATE_Decimal = 0.15F
Const BASE_PAY_Decimal = 250D
Private Sub calculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calculateButton.Click
'Calculate and display the current amounts and add to totals.
Dim totalPayDecimal, totalAmountDecimal As Decimal
With Me
'Calculate the total pay.
With Me
Try
salesCountInteger = Integer.Parse(.weeklySalesTextBox.Text)
totalPayDecimal = FindCommission(BASE_PAY_Decimal)
.commissionTextBox.Text = totalCommissionDecimal.ToString("N")
.totalSalesTextBox.Text = salesCountInteger.ToString("D")
.totalPayTextBox.Text = totalPayDecimal.ToString("C")
Catch quantityException As FormatException
MessageBox.Show("Input must be numeric.", "Data Entry Error", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
With .weeklySalesTextBox
.Focus()
.SelectAll()
End With
End Try
End With
End With
End Sub
Private Function FindCommission(ByVal totalCommissionDecimal As Decimal) As Decimal
If QUOTA_Decimal >= salesCountInteger Then
Return salesCountInteger * COMMISSION_RATE_Decimal
Else
Return BASE_PAY_Decimal
End If
End Function
End Class
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|