Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming

Reply
 
LinkBack Thread Tools
Old 03-28-07   #1 (permalink)
Spot on there mate
 
t4ct1c47's Avatar
 
intel nvidia

Join Date: Dec 2005
Location: Staffordshire University
Posts: 4,275
Blog Entries: 4

FAQs Submitted: 2
Folding Team Rank: 283
Hardware Reviews: 4
Trader Rating: 3
Default VB.Net how can I sort out the variables for my equation?

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
If anyone can see where I'm going wrong please post here. :P


System: Difference Engine
CPU
Core2 Quad Q6600 @ 3.4Ghz
Motherboard
Asus P5N32-E SLi
Memory
4GB Corsair XMS2 PC6400
Graphics Card
GeForce GTX260 SLi
Hard Drive
320GB (x2) and 120GB (x2) SATA
Sound Card
Asus Xonar D2
Power Supply
Tagan 900W
Case
Thermaltake Shark
CPU cooling
Tuniq Tower 120
OS
Vista x64 Business
Monitor
Samsung 226BW 22" LCD

Last edited by t4ct1c47 : 05-07-07 at 04:10 PM.
t4ct1c47 is online now I fold for Overclock.net Overclocked Account t4ct1c47's Gallery   Reply With Quote
Old 03-28-07   #2 (permalink)
Programmer
 
stupid's Avatar
 
amd nvidia

Join Date: Jan 2006
Location: Fahaheel, Kuwait
Posts: 1,239

Rep: 147 stupid is acknowledged by manystupid is acknowledged by many
Unique Rep: 116
FAQs Submitted: 1
Trader Rating: 4
Default

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

System: Minazo
CPU
Opteron 1210
Motherboard
Biostar TForce 550 SE
Memory
2x1GB G.Skill DDR2 800
Graphics Card
eVGA 8800GT
Hard Drive
500GB 16MB Buf Samsung
Power Supply
Corsair HX520W Modular
Case
CoolerMaster Centurion 5
CPU cooling
CoolerMaster GeminII & Scythe SFF21Ds
GPU cooling
Accelero S1 & Scythe SFF21D
OS
XP Pro SP2
Monitor
Dual monitors: 22" & 19" Widescreens
stupid is offline   Reply With Quote
Old 03-28-07   #3 (permalink)
Programmer
 
stupid's Avatar
 
amd nvidia

Join Date: Jan 2006
Location: Fahaheel, Kuwait
Posts: 1,239

Rep: 147 stupid is acknowledged by manystupid is acknowledged by many
Unique Rep: 116
FAQs Submitted: 1
Trader Rating: 4
Default I think I might have an idea

In these two lines:
Code:
If txtSales.Text > "0" And txtSales.Text < "10001" Then
and
Code:
ElseIf txtSales.Text > "10000" And txtSales.Text < "20001" Then
you are comparing text values, text values can not be compared in this sense - you need to parse these into numbers.

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
Then you can simply display
Code:
MessageBox.Show("Commission: £" & FinalCom, sName, MessageBoxButtons.OK, MessageBoxIcon.Information)
I feel it is it is cleaner code.
__________________
"If there is a god, I hope he has a good excuse"
Woody Allen

System: Minazo
CPU
Opteron 1210
Motherboard
Biostar TForce 550 SE
Memory
2x1GB G.Skill DDR2 800
Graphics Card
eVGA 8800GT
Hard Drive
500GB 16MB Buf Samsung
Power Supply
Corsair HX520W Modular
Case
CoolerMaster Centurion 5
CPU cooling
CoolerMaster GeminII & Scythe SFF21Ds
GPU cooling
Accelero S1 & Scythe SFF21D
OS
XP Pro SP2
Monitor
Dual monitors: 22" & 19" Widescreens
stupid is offline   Reply With Quote
Old 03-29-07   #4 (permalink)
Spot on there mate
 
t4ct1c47's Avatar
 
intel nvidia

Join Date: Dec 2005
Location: Staffordshire University
Posts: 4,275
Blog Entries: 4

FAQs Submitted: 2
Folding Team Rank: 283
Hardware Reviews: 4
Trader Rating: 3
Default

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!

System: Difference Engine
CPU
Core2 Quad Q6600 @ 3.4Ghz
Motherboard
Asus P5N32-E SLi
Memory
4GB Corsair XMS2 PC6400
Graphics Card
GeForce GTX260 SLi
Hard Drive
320GB (x2) and 120GB (x2) SATA
Sound Card
Asus Xonar D2
Power Supply
Tagan 900W
Case
Thermaltake Shark
CPU cooling
Tuniq Tower 120
OS
Vista x64 Business
Monitor
Samsung 226BW 22" LCD

Last edited by t4ct1c47 : 03-29-07 at 04:05 AM.
t4ct1c47 is online now I fold for Overclock.net Overclocked Account t4ct1c47's Gallery   Reply With Quote
Old 03-29-07   #5 (permalink)
Programmer
 
stupid's Avatar
 
amd nvidia

Join Date: Jan 2006
Location: Fahaheel, Kuwait
Posts: 1,239

Rep: 147 stupid is acknowledged by manystupid is acknowledged by many
Unique Rep: 116
FAQs Submitted: 1
Trader Rating: 4
Default

glad to help
__________________
"If there is a god, I hope he has a good excuse"
Woody Allen

System: Minazo
CPU
Opteron 1210
Motherboard
Biostar TForce 550 SE
Memory
2x1GB G.Skill DDR2 800
Graphics Card
eVGA 8800GT
Hard Drive
500GB 16MB Buf Samsung
Power Supply
Corsair HX520W Modular
Case
CoolerMaster Centurion 5
CPU cooling
CoolerMaster GeminII & Scythe SFF21Ds
GPU cooling
Accelero S1 & Scythe SFF21D
OS
XP Pro SP2
Monitor
Dual monitors: 22" & 19" Widescreens
stupid is offline   Reply With Quote
Old 04-30-07   #6 (permalink)
Spot on there mate
 
t4ct1c47's Avatar
 
intel nvidia

Join Date: Dec 2005
Location: Staffordshire University
Posts: 4,275
Blog Entries: 4

FAQs Submitted: 2
Folding Team Rank: 283
Hardware Reviews: 4
Trader Rating: 3
Default

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
And this is from the actual click event I was trying to code.

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

System: Difference Engine
CPU
Core2 Quad Q6600 @ 3.4Ghz
Motherboard
Asus P5N32-E SLi
Memory
4GB Corsair XMS2 PC6400
Graphics Card
GeForce GTX260 SLi
Hard Drive
320GB (x2) and 120GB (x2) SATA
Sound Card
Asus Xonar D2
Power Supply
Tagan 900W
Case
Thermaltake Shark
CPU cooling
Tuniq Tower 120
OS
Vista x64 Business
Monitor
Samsung 226BW 22" LCD

Last edited by t4ct1c47 : 05-07-07 at 04:10 PM.
t4ct1c47 is online now I fold for Overclock.net Overclocked Account t4ct1c47's Gallery   Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -4. The time now is 01:55 PM.


Overclock.net is a Carbon Neutral Site Creative Commons License Internet Security By ControlScan

Terms of Service / Forum Rules | Privacy Policy | Advertising | Become an Official Vendor
Copyright © 2008 Shogun Interactive Development. Most rights reserved.
Page generated in 0.24806 seconds with 8 queries