|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming | |
VB.Net how can I sort out the variables for my equation?
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | ||||||||||||
|
Spot on there mate
![]() ![]() |
Hi all,
I'm haveing probelms getting a messagebox to display the total commission earned from a value entered into a text box. This text box allows values between 1 and 20001 and the message box is supposed to show how much commission has been earned on the following rates; up to 10000 is 4% commission (200 entered into text box should show 8 in the message box) anything over 10000 is worked out at 7% (for 11000 it would be 400 (from first 10000) + 7 from the remaining 100. I hope that makes sense and I'd really appreciate it if someone could tell me what I'm doint wrong with the code. I'm useing Visual Basic 2005 Express Edition and have Option Strict ON and Option Explicit ON. Here is the code in my button click event I have so far but they bring up all sorts of daft values; Code:
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Dim sName As String
sName = txtName.Text
Dim dSales As Decimal
dSales = Decimal.Parse(txtSales.Text)
Dim d4Com As Decimal
d4Com = dSales / 100 * 4
Dim d7Com As Decimal
d7Com = (dSales - 10000) / (100 * 7) + d4Com
Dim FinalCom As Decimal
FinalCom = d4Com + d7Com
If txtSales.Text > "0" And txtSales.Text < "10001" Then
MessageBox.Show("Commission: £" & d4Com, sName, MessageBoxButtons.OK, MessageBoxIcon.Information)
ElseIf txtSales.Text > "10000" And txtSales.Text < "20001" Then
MessageBox.Show("Commission: £" & FinalCom, sName, MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End sub
![]()
Last edited by t4ct1c47 : 05-07-07 at 04:10 PM. |
||||||||||||
|
|
|
|
#2 (permalink) | ||||||||||||
|
Programmer
|
Can we get some examples of your inputs and outputs to better troubleshoot?
__________________
"If there is a god, I hope he has a good excuse" Woody Allen
|
||||||||||||
|
|
|
|
|
#3 (permalink) | ||||||||||||
|
Programmer
|
In these two lines:
Code:
If txtSales.Text > "0" And txtSales.Text < "10001" Then Code:
ElseIf txtSales.Text > "10000" And txtSales.Text < "20001" Then you already have your sales parsed into a number as 'dSales', so compare that with numeric values and you should be ok. Please let me know if this doesn't fix the problem. ------------------------------------------ On another note, I would just have one display clause and move the if statement to be something like (keep in mind I am a C#er, so this might not be 100% correct) Code:
Dim d7Com As Decimal d7Com = 0 If dSales > "10000" Then d7Com = (dSales - 10000) / (100 * 7) + d4Com End If Code:
MessageBox.Show("Commission: £" & FinalCom, sName, MessageBoxButtons.OK, MessageBoxIcon.Information)
__________________
"If there is a god, I hope he has a good excuse" Woody Allen
|
||||||||||||
|
|
|
|
|
#4 (permalink) | ||||||||||||
|
Spot on there mate
![]() ![]() |
Thankyou very much stupid! I never thought I had to parse the inputted text seeing as I already had the dSales variable parsed, which referred to that text box. I've since entered the appropriate code based on your input and its working now. Rep +1!
![]()
Last edited by t4ct1c47 : 03-29-07 at 04:05 AM. |
||||||||||||
|
|
|
|
#5 (permalink) | ||||||||||||
|
Programmer
|
glad to help
![]()
__________________
"If there is a god, I hope he has a good excuse" Woody Allen
|
||||||||||||
|
|
|
|
|
#6 (permalink) | ||||||||||||
|
Spot on there mate
![]() ![]() |
Just thought I'd make an update to this ageing thread with the working code I ended up useing, just incase some poor geezer out there uses Google to find help on their assignment.
These variables needed to be declared in the Public section, so that they could be used by any of the private events. Code:
Public Class frmCommission
'These aren't private variables so they are put here to be used as necessary
'Store all combined commission values in memory
Dim dTotalCommission As Decimal
'Store the highest individual commission
Dim dHighestCommission As Decimal
'Put the value in the Name text box into memory
Dim sHighestName As String
Code:
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
'Store the Name value for display in the message box
Dim sName As String
sName = txtName.Text
'Put value in Sales text box into memory
Dim dSales As Decimal
'Commission variable
Dim dCommission As Decimal
'Message box will prompt the user if no data entered
If txtName.Text = "" Then
MessageBox.Show("Please enter a name", "No User Name", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
ElseIf txtSales.Text = "" Then
MessageBox.Show("Please enter a sales amount", "No Sales Amount", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
'Work out commission for based on 4% for under 10001
Else : dSales = Decimal.Parse(txtSales.Text)
If dSales >= 10000 Then
dCommission = CDec((dSales - 10000) * 0.07 + 400)
MessageBox.Show("Total Comission: £" & dCommission, sName.ToString, MessageBoxButtons.OK, MessageBoxIcon.Information)
'Clear the text boxes and focus
txtName.Focus()
txtName.Clear()
txtSales.Clear()
'Adds the users commission to the total commission variable
dTotalCommission = dTotalCommission + dCommission
'Work out commission based on 4% on first 10000 and 7% for any remainder
Else : dCommission = CDec(dSales * 0.04)
MessageBox.Show("Total Comission: £" & dCommission, txtName.Text, MessageBoxButtons.OK, MessageBoxIcon.Information)
'Clear the text boxes and focus
txtName.Focus()
txtName.Clear()
txtSales.Clear()
'Adds users commsission to the total commission variable
dTotalCommission = dTotalCommission + dCommission
End If
End If
'Adds the user name and commission to memory if they are highest so far
If dCommission > dHighestCommission Then
dHighestCommission = dCommission
sHighestName = sName
End If
End Sub
Last edited by t4ct1c47 : 05-07-07 at 04:10 PM. |
||||||||||||
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|