Wrox Programmer Forums
|
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
 
Old October 30th, 2005, 01:06 PM
Authorized User
 
Join Date: Aug 2005
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default fractions to decimals

How can I convert a fraction in a text box to a decimal in another text box?

THanks

 
Old October 30th, 2005, 04:59 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

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
 
Old October 30th, 2005, 09:24 PM
Authorized User
 
Join Date: Aug 2005
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

 
Old October 30th, 2005, 09:25 PM
Authorized User
 
Join Date: Aug 2005
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

 
Old October 30th, 2005, 10:19 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

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
 
Old November 2nd, 2005, 05:37 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Decimals in charts chetuzz2 Excel VBA 0 July 29th, 2008 02:30 AM
Thousands and Decimals - Notation fskilnik Dreamweaver (all versions) 3 October 4th, 2005 02:35 PM
more decimals fskilnik Dreamweaver (all versions) 2 September 29th, 2005 07:05 AM
Displaying decimals in C# alfonz ASP.NET 1.0 and 1.1 Basics 3 September 20th, 2004 01:51 PM
truncating to 2 decimals msrnivas Classic ASP Components 4 July 7th, 2004 02:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.