|
-
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
-
Oct 16th, 2006, 04:45 PM
#2
Re: Trying to write a function to calculate commission
This is unnecessary:
VB Code:
With Me
'Calculate the total pay.
With Me
Also, if you are checking if the sales count is greater than or equal to the quota, it would look like this:
VB Code:
If QUOTA_Decimal <= salesCountInteger Then
-
Oct 16th, 2006, 05:19 PM
#3
Thread Starter
New Member
Re: Trying to write a function to calculate commission
Thanks I understand that part. I just can't get the function right to send the commission earned back to the calculate function.
-
Oct 16th, 2006, 05:51 PM
#4
Re: Trying to write a function to calculate commission
Use
VB Code:
Option Strict On
Option Explicit On
To prevent the use of variants and implicit conversion.
Then
VB Code:
Const QUOTA_Decimal As Decimal = 1000
Const COMMISSION_RATE_Decimal As Decimal = 0.15D
Const BASE_PAY_Decimal As Decimal = 250D
-
Oct 16th, 2006, 06:42 PM
#5
Re: Trying to write a function to calculate commission
I can't quite understand some of the code but I think you said they get commission on top of base pay if they have exceeded their targets. Does your current code not give them either just commission (no base pay) or just the pay without the commission? I don't see where you have
TotalPay = BaseLinePay + Calculated Commission
Or have I missed it?
Stim
-
Oct 16th, 2006, 08:21 PM
#6
Thread Starter
New Member
Re: Trying to write a function to calculate commission
I am sorry I didn't label my code. The way the program is suppose to work is that if the salesperson gets 1000 or more in sales they get 15% commission on that amount plus their base pay. If they dont' make more that 1000 in sales they just get their base pay. The problem i am having is writing the function to calculate the commission of:
If they make 1000(QUOTA) or more
Quota * Commission
If Not
they just get basPay
I can't get this to work in the fucntion.
Thanks
-
Oct 17th, 2006, 03:04 AM
#7
Re: Trying to write a function to calculate commission
I've adopted a slightly different method just to try and get things a little straighter. I'm sure you have too many variables declared...
Place 4 text boxes and a button on a form:
Call the text boxes:
txtWeeklySales
txtTotalCommission
txtBasePay
txtTotalPay
Then add the following code:
VB Code:
Option Explicit On
Option Strict On
Public Class Form1
Dim intSales_Count As Integer
Dim dmlTotalCommission, dmlTotalPay As Decimal
Const QUOTA_Decimal As Decimal = 1000
Const COMMISSION_RATE_Decimal As Decimal = 0.15D
Const BASE_PAY_Decimal As Decimal = 250
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
intSales_Count = Integer.Parse(Me.txtWeeklySales.Text) 'Find Weekly Sales Made
dmlTotalCommission = CalculateCommission(intSales_Count) 'Calculate Commission
Me.txtTotalCommission.Text = CStr(dmlTotalCommission) 'Show the commission they have
Me.txtBasePay.Text = CStr(BASE_PAY_Decimal) 'I added a text box to display base line pay
dmlTotalPay = BASE_PAY_Decimal + dmlTotalCommission 'Add the base pay + any commission
Me.txtTotalPay.Text = CStr(dmlTotalPay) 'Display total pay
End Sub
Private Function CalculateCommission(ByVal intSales_Count As Integer) As Decimal
If QUOTA_Decimal <= intSales_Count Then
Return intSales_Count * COMMISSION_RATE_Decimal 'This is just commission, base pay has to be added too
Else
Return 0 'Don't return the base line pay as the commission!
End If 'That's what I was trying to say in my previous post
End Function 'You didn't separate them out
End Class
I hope this code is correct, if people disagree with it please let me know and I'll change it.
You will want to put in your Try statements and so on. You should check out this forum for the IsNumeric command as well to help prevent wrong input from getting into the text boxes.
Stim
Last edited by stimbo; Nov 7th, 2006 at 10:32 AM.
-
Oct 17th, 2006, 08:34 PM
#8
Thread Starter
New Member
Re: Trying to write a function to calculate commission
Thank you very much. I understand exactly what you are talking about now. This can be very confusing. LOL Thanks!
-
Oct 18th, 2006, 03:19 AM
#9
Re: Trying to write a function to calculate commission
Remember to mark this thread as Resolved if your question has been answered (see the tools options).
Stim
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
|