calculating commission in VB
 CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

1. Junior Member
Join Date
Apr 2011
Posts
1

calculating commission in VB

I'm really new to VB. This is only the 3 app I've created, and I'm stuck.

I need to code an app that displays total commission earned on sales at different levels. The commission percentage goes up as sales go up.

Should I write a If/else/else/else/else/then statement or something else?

There are 5 different commission levels in the problem. I have my interface designed, but obviously that's the easy part.

Any help would be appreciated.

2. Re: calculating commission in VB

you can use a select case to get what percentage value the commission should be..
Code:
```Select case sales
case < 500
comper = .05
case < 1000
comper = .07
case < 2000
comper = .09
case else
comper = .10
end select
Commission = sales * comper```
It works almost the same as an If Else/else/else but is a little cleaner and easier to adjust at a later time..

3. Junior Member
Join Date
Feb 2014
Posts
3

Re: calculating commission in VB

I am brand new to VB and I am also working on a commission project. I was going to use the if/else/else/then as mentioned above but could not figure out exactly where to place it in the code. I want the commission to be calculated when the btnCalc button is clicked so I thought it should go within that declaration but it doesn't work.

I like the idea of using the Select case method as described by GremlinSA but that still leaves e with where does it fit in the code.

Thanks,
Clyde

4. Re: calculating commission in VB

Why not just create a new function and call it from within the Button_Click event!
Pass it the variable to choose from. ComputeCalc(myValue)

5. Junior Member
Join Date
Feb 2014
Posts
3

Re: calculating commission in VB

I tried that but there are 3 different levels of commissions depending on the amount of sales made. The commission structure is:
= < 100000 is 2%
>100000 but < 400000 is 2000 + 5% of everything over 100000
>400000 is 17000 + 10% of everything over 400000

I thought I had it working but the 5% carried over into the next option so instead of getting 10% of everything over 400000 it was only showing 5%. I have no idea why the 2% did not carry over into the second option but the 5% did carry over to the third.

Thank you for your reply. It will be very helpful if I can figure out how to fix the multiplication problem.
Clyde

6. Super Moderator Power Poster
Join Date
Jul 2008
Location
WV
Posts
5,255

Re: calculating commission in VB

It would help if you showed the code you tried.

in the first case you would just take the percentage of the value
in the next case you would subtract 100000 from the value and then do the percentage on the remainder and add 2000 to that number
in the final case it would be the same except you would be subtracting 400000 from the total and doing the percentage on that remainder and adding the 17000 to that number

Something like
Code:
```Select case TotalVal
Case < 100001
Comission=TotalVal*.02
Case < 400001
Comission=2000+((TotalVal-100000)*.05)
Case Else
Comission=17000+((TotalVal-400000)*.1)
End Select```

7. Junior Member
Join Date
Feb 2014
Posts
3

Re: calculating commission in VB

Thanks DataMiser,
I actually understood what you were suggesting and was able to use the code to finish the project.

Sorry it took me so long to get back here to rate your post and say think you.

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•