Results 1 to 30 of 30

Thread: Simple Math Equation wont work!

  1. #1

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Simple Math Equation wont work!

    I am tryign to get the % of these totals and it wont work, it wont * the number by 100.
    It gives me the percentage as a whole number 7.4521574 etc, but now i want to turn it into a percentage .74521574 etc.

    VB Code:
    1. Option Explicit
    2.  
    3. Dim num1 As Double
    4. Dim num2 As Double
    5. Dim answer1 As Double
    6.  
    7. ' This calculates the tax credit on parts
    8. Private Sub Command1_Click()
    9. Text3.Text = Text1.Text / Text2.Text * 100 ' this is where it wont do the final part of the calcuation
    10. End Sub

  2. #2
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Simple Math Equation wont work!

    text3.text = (val(text1.text) / val (text2.text)) * 100

  3. #3
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Simple Math Equation wont work!

    To explain the val() function further have a look

    http://www.vbforums.com/showpost.php...2&postcount=16


  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Simple Math Equation wont work!

    How about
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim dblPerCent As Double
    3. dblPerCent = Text1.Text / Text2.Text * 100 ' this is where it wont do the final part of the calcuation
    4. dblPerCent = Format(dblPerCent, ".0")  'or whatever format you want the number to be in
    5. Text3.Text = dblPercent & "%"
    6. End Sub

  5. #5

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: Simple Math Equation wont work!

    Nope that didnt work

    VB Code:
    1. Option Explicit
    2.  
    3. Dim num1 As Double
    4. Dim num2 As Double
    5. Dim answer1 As Double
    6.  
    7. ' This calculates the tax credit on parts
    8. Private Sub Command1_Click()
    9. Text3.Text = (Val(Text1.Text) / Val(Text2.Text)) * 100
    10. End Sub

  6. #6
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Simple Math Equation wont work!

    are you putting the larger number in the 2nd textbox? because that equation works for me 100%...

    the only problem I could see is if the larger number is in the first textbox..so you would get a value > 1 and it would end up being a larger number

  7. #7
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: Simple Math Equation wont work!

    Quote Originally Posted by joefox
    Nope that didnt work

    VB Code:
    1. Option Explicit
    2.  
    3. Dim num1 As Double
    4. Dim num2 As Double
    5. Dim answer1 As Double
    6.  
    7. ' This calculates the tax credit on parts
    8. Private Sub Command1_Click()
    9. Text3.Text = (Val(Text1.Text) / Val(Text2.Text)) * 100
    10. End Sub
    Can you b a bit more specific. Did you get an error or can you describe exactly what it is (Or is not) doing that it should be?

    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

  8. #8

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: Simple Math Equation wont work!

    Ok here is the issue, i need to have the full % number to figure out the tax, because if not, it will be off by 2 pennies or so, and when you do thousands of tranacations like that a month it gets costly.

    So is there a way to calculate the percentage as the long number, but only show that % as HACK showed us?

    See once i figure this out, i am going to use this number to figure the tax credit on the different shipping rates we have.

    VB Code:
    1. Private Sub Command1_Click()
    2. Dim dblPerCent As Double
    3. dblPerCent = Text1.Text / Text2.Text * 100 ' this is where it wont do the final part of the calcuation
    4. dblPerCent = Format(dblPerCent, ".0")  'or whatever format you want the number to be in
    5. Text3.Text = dblPerCent & "%"
    6. End Sub

  9. #9

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: Simple Math Equation wont work!

    Ok here are the values i got!
    Invoice amount is $9.12
    Tax Amount is .68
    Sales Amount $4.49
    Shipping and Hand: $3.95

    So what i am doing first if figuring out the tax percentage, So i take the Tax Amount / Invoice amount. That will give me the percentage. Then i need take it and * it by the sales amount. This will show the $ back on the part they ordered

  10. #10
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Simple Math Equation wont work!

    Text3.Text = formatcurrency((Val(Text1.Text) / Val(Text2.Text)) * 100,8)

    thatll give it 8 decimal places

  11. #11

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: Simple Math Equation wont work!

    When i put what you have above it just gives me 7.458274...
    I want the percentage to be .745215454....

  12. #12

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: Simple Math Equation wont work!

    Ohhhh wait im not thinking right!
    NEVERMIND EVERYONE

  13. #13
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Simple Math Equation wont work!

    mind telling us what you were doing? :P

    wait a sec..if you wanted it to not be a number greater than 1...then why were you multiplynig it by 100 ?
    Last edited by kfcSmitty; Jun 2nd, 2005 at 01:36 PM.

  14. #14

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: Simple Math Equation wont work!

    Ok this is what i have, but for some reason i double check the calculation and it dosent come out right.

    The way i check just to make sure is, i will add shipping and handling + sales amount then * it by the tax amount, and it should come out to the invoice amount, and it dosent.

    VB Code:
    1. Public Sub Command1_Click()
    2. Text3.Text = (Val(Text1.Text) / Val(Text2.Text)) * 100
    3. End Sub
    4.  
    5. Public Sub Command2_Click()
    6. ' this is where i can put in the value of the part ($4.49) and then have it * by the percentage of the tax
    7. Text5.Text = (Val(Text4.Text) * Val(Text3.Text))
    8. End Sub
    9.  
    10. Private Sub Form_Load()
    11.     Load_Default_Values
    12. End Sub
    13.  
    14. Private Sub Load_Default_Values()
    15.     Text1.Text = ""
    16.     Text2.Text = ""
    17.     Text3.Text = ""
    18.     Text4.Text = ""
    19.     Text5.Text = ""
    20. End Sub

  15. #15
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Simple Math Equation wont work!

    have you done these things on a calculator beforehand to ensure that the formula is indeed correct?

  16. #16

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: Simple Math Equation wont work!

    ? what

  17. #17
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Simple Math Equation wont work!

    Take the #'s you're trying to calculate in VB.

    Write them down, and then do the math on a calculator.

    It may be the formula you're using that is giving the incorrect value, not an error in the code.

  18. #18

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: Simple Math Equation wont work!

    Yep works right!

  19. #19
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Simple Math Equation wont work!

    so whats the exact equation you're punching in on the calculator?

  20. #20

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: Simple Math Equation wont work!

    For some reason, i can not get the percentage of tax right.
    I double check by adding the S&H + the part price * the tax rate, and it should say .68 cents, but it dosent!

  21. #21

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: Simple Math Equation wont work!

    This is all the code i have, i think i need to get the whole number from the first equation about the tax, for some reason its limiting me to 15 or so decmil places, i need it to be enless.

    VB Code:
    1. Option Explicit
    2.  
    3. Dim num1 As Double
    4. Dim num2 As Double
    5. Dim answer1 As Double
    6.  
    7. ' This calculates the tax credit on parts
    8. Public Sub Command1_Click()
    9. Text3.Text = (Val(Text1.Text) / Val(Text2.Text)) * 100
    10. End Sub
    11.  
    12. Public Sub Command2_Click()
    13. Text5.Text = Val(Text4.Text) * Text3.Text
    14. Text5.Text = FormatCurrency(Text5.Text) / 100
    15. End Sub
    16.  
    17. Private Sub Form_Load()
    18.     Load_Default_Values
    19. End Sub
    20.  
    21. Private Sub Load_Default_Values()
    22.     Text1.Text = ""
    23.     Text2.Text = ""
    24.     Text3.Text = ""
    25.     Text4.Text = ""
    26.     Text5.Text = ""
    27. End Sub

  22. #22
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Simple Math Equation wont work!

    remember, the computer uses BEDMAS...so you may need to add brackets in to make sure it does the calculations in the correct order

    what does each textbox contain? text1 and text5 arent really descriptive

    also, it would be helpful if you could give some sample data so i can test

  23. #23

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: Simple Math Equation wont work!

    Ok here is the data I have:

    Invoice Amount (total with everything together) $9.12
    Sales Amount ( 1 part ) $4.49
    Tax AMount (tax changed on part + shipping cost) $.68
    Shipping and handling $3.95

    In textbox1 i put the tax amount
    In textbox2 i put the invoice amount

    then it displays the tax percentage in textbox3

    then i put in the part price in textbox4 and it * by whatever is in textbox3
    and puts that into textbox5

    So the way i double check to make sure its right is, i add shipping and handling + sales amount and then * it by percentage, and it should equal out to the tax amount.


  24. #24
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Simple Math Equation wont work!

    the way I found the percentage was to take (S&H + part)/tax

    if you take S&H + part / tax..you get a decimal...then add 1 to that..and multiply it by S&H + part and you get 9.12

    thatll give you the %..the way you're doing it makes no sense to me..


    doing it your way with a calculator i keep getting 9.069
    Last edited by kfcSmitty; Jun 2nd, 2005 at 02:38 PM.

  25. #25

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: Simple Math Equation wont work!

    Could you help me out with some code to do what you said above?

    VB Code:
    1. Option Explicit
    2.  
    3. Dim num1 As Double
    4. Dim num2 As Double
    5. Dim answer1 As Double
    6.  
    7. ' This calculates the tax credit on parts
    8. Public Sub Command1_Click()
    9. Text3.Text = (Val(Text1.Text) / Val(Text2.Text)) * 100
    10. End Sub
    11.  
    12. Public Sub Command2_Click()
    13. Text5.Text = Val(Text4.Text) * Text3.Text
    14. Text5.Text = FormatCurrency(Text5.Text) / 100
    15. End Sub
    16.  
    17. Private Sub Form_Load()
    18.     Load_Default_Values
    19. End Sub
    20.  
    21. Private Sub Load_Default_Values()
    22.     Text1.Text = ""
    23.     Text2.Text = ""
    24.     Text3.Text = ""
    25.     Text4.Text = ""
    26.     Text5.Text = ""
    27. End Sub

  26. #26
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Simple Math Equation wont work!

    This is assuming you're only trying to find the %, and all the values are given

    VB Code:
    1. Dim SHandPart as double
    2. double = (val(txtShipping.text) + val(txtPart.text))
    3. txttaxpercent = val(txtTax.text) / double

    and that should give you 0.080568720379146919431279620853081

    if you want it to be a percentage, then * by 100

  27. #27

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: Simple Math Equation wont work!

    where woudli put that in my code?

  28. #28

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: Simple Math Equation wont work!

    How would i figure it out, if i didnt know the s+h ?

  29. #29
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Simple Math Equation wont work!

    First of all, the number of digits is not your problem. You can't get better than 15 anyway. This problem will even work with single precision.

    When you store your tax percentage in a text box you are multiplying it by 100 for display purposes only, so when you use it in your calculation you must divide it again by 100.

    VB Code:
    1. 'Store tax percentage in a variable, not in text box
    2. TaxPct = Cdbl(Text1.Text)/Cdbl(Text2.Text)
    3. 'Text3 is for display purposes only
    4. 'No Need to multiply here Format statement does it for you
    5. Text3.Text = Format(Cdbl(Text1.Text) /cdbl( Text2.Text),"0.0%")
    6. 'Now use the variable rather than text3
    7. TaxOnSale = Cdbl(Text2.Text) * TaxPct

    If this does not solve your problem then please supply all the numbers and equations you are using including the equations you are using to do the check for consitency.

  30. #30
    Hyperactive Member shizzy's Avatar
    Join Date
    May 2005
    Location
    Michigan
    Posts
    278

    Re: Simple Math Equation wont work!

    To get a good percentage this is what I did in my grading program:
    VB Code:
    1. Format(strTotGrade, "###%")
    In rare occasion, if I help you, give me some rate points. They help me sleep at night
    WMRR Rockin' the Lakeshore! For all your guitar music needs! For all your guitar purchasing needs!
    AC/DC Rocks! Van Halen! Led Zeppelin!

    my webpage

Posting Permissions

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



Click Here to Expand Forum to Full Width