VB Newbie!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • astarms
    New Member
    • Nov 2006
    • 1

    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!!!
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Originally posted by astarms
    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

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Originally posted by astarms
      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
      Code:
      Dim Msg As String
      Msg = "Price: " & Format(Price) & vbNewLine _
        & "Shares: " & Format(Shares) & vbNewLine _
        & "Total: " & Format(Total) & vbNewLine _
        & "Broker: " & BrokerName & vbNewLine _
        & "Stock: " & Stockname & vbNewLine
        
      If Price <= 50 Then
        Commission = 0.19
      Else
        Commission = 0.26
      End If
      If Shares < 150 Then
        Commission = Commission * 1.5
      End If
      Msg = Msg & "Commission: " & Format(Commission, "%")
      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.

      Comment

      • superdudes
        New Member
        • Oct 2006
        • 5

        #4
        Originally posted by Killer42
        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

        Code:
        FormatPercent()

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          Originally posted by superdudes
          I am pretty sure it is
          Code:
          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.

          Comment

          Working...