467,151 Members | 900 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,151 developers. It's quick & easy.

VB Newbie!

I am new to VB and have to make a commission calculator, but I am running into problems.

I have four text boxes where the following information will be added by the viewer:

- The Stock Broker's Name
- The Stock Name
- The Price Per Share
- The Number of Shares

I then have to multiply the number of shares by the price of the shares and output it in a message box. This part I have been able to do.

The problem I have not been able to accomplish is outputing the broker's and stock's names in the same message box as well as make a conditional statement to be placed underneath the total commission.

If the price of shares is less than or equal to $50 then I have to tell them their commission rate is 19% If the price is greater than $50 then the rate is 26%. And lastly, if the number of shares is below 150 then multiply 1.5 times rate.

I believe that I need nested IfElse statements to do the first conditional section and an AndAlso statement for the shares condition. i just don't know how to write the syntax correctly.

Help!!!
Nov 4 '06 #1
  • viewed: 1496
Share:
4 Replies
1GB
I am new to VB and have to make a commission calculator, but I am running into problems.

I have four text boxes where the following information will be added by the viewer:

- The Stock Broker's Name
- The Stock Name
- The Price Per Share
- The Number of Shares

I then have to multiply the number of shares by the price of the shares and output it in a message box. This part I have been able to do.

The problem I have not been able to accomplish is outputing the broker's and stock's names in the same message box as well as make a conditional statement to be placed underneath the total commission.

If the price of shares is less than or equal to $50 then I have to tell them their commission rate is 19% If the price is greater than $50 then the rate is 26%. And lastly, if the number of shares is below 150 then multiply 1.5 times rate.

I believe that I need nested IfElse statements to do the first conditional section and an AndAlso statement for the shares condition. i just don't know how to write the syntax correctly.

Help!!!
Hi, if you would be so kind as to post the code you already have we will be in a better position to assist you.

Thanks
Nov 4 '06 #2
Expert 8TB
I am new to VB and have to make a commission calculator, but I am running into problems.

I have four text boxes where the following information will be added by the viewer:

- The Stock Broker's Name
- The Stock Name
- The Price Per Share
- The Number of Shares

I then have to multiply the number of shares by the price of the shares and output it in a message box. This part I have been able to do.

The problem I have not been able to accomplish is outputing the broker's and stock's names in the same message box as well as make a conditional statement to be placed underneath the total commission.

If the price of shares is less than or equal to $50 then I have to tell them their commission rate is 19% If the price is greater than $50 then the rate is 26%. And lastly, if the number of shares is below 150 then multiply 1.5 times rate.

I believe that I need nested IfElse statements to do the first conditional section and an AndAlso statement for the shares condition. i just don't know how to write the syntax correctly.

Help!!!
Assuming you have the various pieces of information in appropriate variables already, you could build a string to display, something like this
Expand|Select|Wrap|Line Numbers
  1. Dim Msg As String
  2. Msg = "Price: " & Format(Price) & vbNewLine _
  3.   & "Shares: " & Format(Shares) & vbNewLine _
  4.   & "Total: " & Format(Total) & vbNewLine _
  5.   & "Broker: " & BrokerName & vbNewLine _
  6.   & "Stock: " & Stockname & vbNewLine
  7.  
  8. If Price <= 50 Then
  9.   Commission = 0.19
  10. Else
  11.   Commission = 0.26
  12. End If
  13. If Shares < 150 Then
  14.   Commission = Commission * 1.5
  15. End If
  16. Msg = Msg & "Commission: " & Format(Commission, "%")
  17. MsgBox Msg
This is just off the top of my head, and not tested. But it should help to get you going. Also, I couldn't remember the right way to format the percentage. Check out the Format() function in online help for details.
Nov 5 '06 #3
Also, I couldn't remember the right way to format the percentage. Check out the Format() function in online help for details.
I am pretty sure it is

Expand|Select|Wrap|Line Numbers
  1. FormatPercent()
Nov 6 '06 #4
Expert 8TB
I am pretty sure it is
Expand|Select|Wrap|Line Numbers
  1. FormatPercent()
Neat! Thanks for that, I hadn't actually encountered FormatPercent, or didn't remember it. I normally just use Format() with various formatting strings.
Nov 6 '06 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Philippe C. Martin | last post: by
reply views Thread by Twayne | last post: by
16 posts views Thread by Raxit@MyKavita.com | last post: by
10 posts views Thread by Peter Michaux | last post: by
2 posts views Thread by r_ahimsa_m@poczta.onet.pl | last post: by
5 posts views Thread by Dave | last post: by
5 posts views Thread by SharkD | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.