|
-
Jun 2nd, 2005, 12:59 PM
#1
Thread Starter
Frenzied Member
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:
Option Explicit
Dim num1 As Double
Dim num2 As Double
Dim answer1 As Double
' This calculates the tax credit on parts
Private Sub Command1_Click()
Text3.Text = Text1.Text / Text2.Text * 100 ' this is where it wont do the final part of the calcuation
End Sub
-
Jun 2nd, 2005, 01:02 PM
#2
Re: Simple Math Equation wont work!
text3.text = (val(text1.text) / val (text2.text)) * 100
-
Jun 2nd, 2005, 01:07 PM
#3
Re: Simple Math Equation wont work!
-
Jun 2nd, 2005, 01:09 PM
#4
Re: Simple Math Equation wont work!
How about
VB Code:
Private Sub Command1_Click()
Dim dblPerCent As Double
dblPerCent = Text1.Text / Text2.Text * 100 ' this is where it wont do the final part of the calcuation
dblPerCent = Format(dblPerCent, ".0") 'or whatever format you want the number to be in
Text3.Text = dblPercent & "%"
End Sub
-
Jun 2nd, 2005, 01:11 PM
#5
Thread Starter
Frenzied Member
Re: Simple Math Equation wont work!
Nope that didnt work
VB Code:
Option Explicit
Dim num1 As Double
Dim num2 As Double
Dim answer1 As Double
' This calculates the tax credit on parts
Private Sub Command1_Click()
Text3.Text = (Val(Text1.Text) / Val(Text2.Text)) * 100
End Sub
-
Jun 2nd, 2005, 01:14 PM
#6
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
-
Jun 2nd, 2005, 01:15 PM
#7
Re: Simple Math Equation wont work!
 Originally Posted by joefox
Nope that didnt work
VB Code:
Option Explicit
Dim num1 As Double
Dim num2 As Double
Dim answer1 As Double
' This calculates the tax credit on parts
Private Sub Command1_Click()
Text3.Text = (Val(Text1.Text) / Val(Text2.Text)) * 100
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
-
Jun 2nd, 2005, 01:16 PM
#8
Thread Starter
Frenzied Member
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:
Private Sub Command1_Click()
Dim dblPerCent As Double
dblPerCent = Text1.Text / Text2.Text * 100 ' this is where it wont do the final part of the calcuation
dblPerCent = Format(dblPerCent, ".0") 'or whatever format you want the number to be in
Text3.Text = dblPerCent & "%"
End Sub
-
Jun 2nd, 2005, 01:19 PM
#9
Thread Starter
Frenzied Member
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
-
Jun 2nd, 2005, 01:24 PM
#10
Re: Simple Math Equation wont work!
Text3.Text = formatcurrency((Val(Text1.Text) / Val(Text2.Text)) * 100,8)
thatll give it 8 decimal places
-
Jun 2nd, 2005, 01:27 PM
#11
Thread Starter
Frenzied Member
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....
-
Jun 2nd, 2005, 01:27 PM
#12
Thread Starter
Frenzied Member
Re: Simple Math Equation wont work!
Ohhhh wait im not thinking right!
NEVERMIND EVERYONE
-
Jun 2nd, 2005, 01:28 PM
#13
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.
-
Jun 2nd, 2005, 01:34 PM
#14
Thread Starter
Frenzied Member
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:
Public Sub Command1_Click()
Text3.Text = (Val(Text1.Text) / Val(Text2.Text)) * 100
End Sub
Public Sub Command2_Click()
' this is where i can put in the value of the part ($4.49) and then have it * by the percentage of the tax
Text5.Text = (Val(Text4.Text) * Val(Text3.Text))
End Sub
Private Sub Form_Load()
Load_Default_Values
End Sub
Private Sub Load_Default_Values()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
End Sub
-
Jun 2nd, 2005, 01:37 PM
#15
Re: Simple Math Equation wont work!
have you done these things on a calculator beforehand to ensure that the formula is indeed correct?
-
Jun 2nd, 2005, 01:39 PM
#16
Thread Starter
Frenzied Member
Re: Simple Math Equation wont work!
-
Jun 2nd, 2005, 01:47 PM
#17
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.
-
Jun 2nd, 2005, 01:49 PM
#18
Thread Starter
Frenzied Member
Re: Simple Math Equation wont work!
-
Jun 2nd, 2005, 01:50 PM
#19
Re: Simple Math Equation wont work!
so whats the exact equation you're punching in on the calculator?
-
Jun 2nd, 2005, 01:53 PM
#20
Thread Starter
Frenzied Member
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!
-
Jun 2nd, 2005, 01:56 PM
#21
Thread Starter
Frenzied Member
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:
Option Explicit
Dim num1 As Double
Dim num2 As Double
Dim answer1 As Double
' This calculates the tax credit on parts
Public Sub Command1_Click()
Text3.Text = (Val(Text1.Text) / Val(Text2.Text)) * 100
End Sub
Public Sub Command2_Click()
Text5.Text = Val(Text4.Text) * Text3.Text
Text5.Text = FormatCurrency(Text5.Text) / 100
End Sub
Private Sub Form_Load()
Load_Default_Values
End Sub
Private Sub Load_Default_Values()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
End Sub
-
Jun 2nd, 2005, 01:57 PM
#22
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
-
Jun 2nd, 2005, 02:19 PM
#23
Thread Starter
Frenzied Member
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.
-
Jun 2nd, 2005, 02:33 PM
#24
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.
-
Jun 2nd, 2005, 02:53 PM
#25
Thread Starter
Frenzied Member
Re: Simple Math Equation wont work!
Could you help me out with some code to do what you said above? 
VB Code:
Option Explicit
Dim num1 As Double
Dim num2 As Double
Dim answer1 As Double
' This calculates the tax credit on parts
Public Sub Command1_Click()
Text3.Text = (Val(Text1.Text) / Val(Text2.Text)) * 100
End Sub
Public Sub Command2_Click()
Text5.Text = Val(Text4.Text) * Text3.Text
Text5.Text = FormatCurrency(Text5.Text) / 100
End Sub
Private Sub Form_Load()
Load_Default_Values
End Sub
Private Sub Load_Default_Values()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
End Sub
-
Jun 2nd, 2005, 03:01 PM
#26
Re: Simple Math Equation wont work!
This is assuming you're only trying to find the %, and all the values are given
VB Code:
Dim SHandPart as double
double = (val(txtShipping.text) + val(txtPart.text))
txttaxpercent = val(txtTax.text) / double
and that should give you 0.080568720379146919431279620853081
if you want it to be a percentage, then * by 100
-
Jun 2nd, 2005, 03:27 PM
#27
Thread Starter
Frenzied Member
Re: Simple Math Equation wont work!
where woudli put that in my code?
-
Jun 2nd, 2005, 03:51 PM
#28
Thread Starter
Frenzied Member
Re: Simple Math Equation wont work!
How would i figure it out, if i didnt know the s+h ?
-
Jun 2nd, 2005, 04:41 PM
#29
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:
'Store tax percentage in a variable, not in text box
TaxPct = Cdbl(Text1.Text)/Cdbl(Text2.Text)
'Text3 is for display purposes only
'No Need to multiply here Format statement does it for you
Text3.Text = Format(Cdbl(Text1.Text) /cdbl( Text2.Text),"0.0%")
'Now use the variable rather than text3
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.
-
Jun 2nd, 2005, 05:57 PM
#30
Hyperactive Member
Re: Simple Math Equation wont work!
To get a good percentage this is what I did in my grading program:
VB Code:
Format(strTotGrade, "###%")
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|