 |
| Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

October 30th, 2005, 01:06 PM
|
|
Authorized User
|
|
Join Date: Aug 2005
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
fractions to decimals
How can I convert a fraction in a text box to a decimal in another text box?
THanks
|
|

October 30th, 2005, 04:59 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
|
|
Hi Mjuliao,
Any chance you could post on example of what the fraction might look like? I have some ideas of how you might be able to work this out.
Thanks
Mike
Mike
EchoVue.com
|
|

October 30th, 2005, 09:24 PM
|
|
Authorized User
|
|
Join Date: Aug 2005
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Well actually what I need is this:
I have 2 textboxes next to each other txtA and txtB. When I introduce a size like 12 1/2" I need to put the 12 in txtA and the 1/2 in the txtB. Then I calculate a price base on the size but if the size is 12 1/2" is considered 13" to price it. So the idea is that, if I only input 12" it will use the size as 12" but if I input 12 1/2" it will use the size as 13".
I was looking for a convertion into decimals since I can roundup(txtA + txtB,2) and that will know if the size is 12" or 13" based on 12.5 >>> 13. That was my idea but when access sees there is a 1/2 entered in txtB it will display #Error since the formula txtA + txtB inst capable of adding these.
THat was what I figure a good way to do it, but If you know a better way since this is a common problem in quotations, please let me know.
For example,
I input in txtA this 5/8 and I wan
|
|

October 30th, 2005, 09:25 PM
|
|
Authorized User
|
|
Join Date: Aug 2005
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Well actually what I need is this:
I have 2 textboxes next to each other txtA and txtB. When I introduce a size like 12 1/2" I need to put the 12 in txtA and the 1/2 in the txtB. Then I calculate a price base on the size but if the size is 12 1/2" is considered 13" to price it. So the idea is that, if I only input 12" it will use the size as 12" but if I input 12 1/2" it will use the size as 13".
I was looking for a convertion into decimals since I can roundup(txtA + txtB,2) and that will know if the size is 12" or 13" based on 12.5 >>> 13. That was my idea but when access sees there is a 1/2 entered in txtB it will display #Error since the formula txtA + txtB inst capable of adding these.
THat was what I figure a good way to do it, but If you know a better way since this is a common problem in quotations, please let me know.
|
|

October 30th, 2005, 10:19 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
|
|
This isn't pretty, but here is one possible solution:
My assumption is that you would never have a fraction less than 1/8"
For TxtA, add the following on the afterUpdate event...
Dim intLength as integer
Dim lngWhole as long
Dim lngFraction as long
Dim strFraction as string
lngWhole = 0
lngFraction = 0
strFraction = Right(txtA, 4)
if mid(strFraction,2,1) = "/" then
lngFraction = val(mid(strFraction,1,1)) / val(mid(strFraction,3,1))
lngWhole = Left(txtA, len(txtA)-4)
else
lngWhole = Left(txtA, len(txtA)-1)
end if
txtB = roundup(lngWhole + lngFraction,0)
I think that should work, if not it should give you an idea of how it could work.
Mike
EchoVue.com
|
|

November 2nd, 2005, 05:37 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
|
|
Well, if you ALWAYS evaluate a size that's larger than, say 12, as 13 then you don't have to calculate anything. For example, if txtA = 12 and txtB = "1/8" and if ANYTHING over 12 is considered 13, then
all you have to do say something like
If IsNull(Me.txtB) Then
curPrice = Me.txtA * curPricePerSize
Else
curPrice = (Me.txtA + 1) * curPricePerSize
End If
That is, if the size is ANYTHING over a whole number, go up one.
Now if this assumption is wrong then it's a bit more complicated but not much. Say that the price goes up ONLY if txtB evaluates to 0.5 or greater. That means if txtB = "1/8" then the price is that for 12, but if txtB = "5/8" then the price is that for 13. In that case you can use the EVAL() function.
If CSng(Eval(Nz(Me.txtB,"0"))) < 0.5 Then
curPrice = Me.txtA * curPricePerSize
Else
curPrice = (Me.txtA + 1) * curPricePerSize
End If
The EVAL() function will take something like "1/8" and evaluate it, that is, divide one by eight and give you a value. The CSng function will turn the result into datatype Single.
I haven't tested this so there may be some trial and error involved.
Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
|
|
 |