10 Replies Latest reply on Jun 29, 2012 1:58 PM by comment

# Calculations using Variables

Is it possible to combine these five functions into one calculation?

//Truncate ( BendDiameter/12 ;0 )

//BendDiameter-(BendDiameter1stCal*12)

//Truncate (BendDiameter2ndCal/1 ; 0 )

//Fractions32 (BendDiameter2ndCal - BendDiameter3rdCal)

//If ( BendDiameter4thCal = +1 ; BendDiameter1stCal & "'" & " - " & BendDiameter3rdCal+1 & """ ; BendDiameter1stCal & "'" & " - " & BendDiameter3rdCal & " " & BendDiameter4thCal & """)

What I am trying to accomplish is taking a number that is in inches convert it to feet & inches for a printed display. I can do this with 5 seperate fields one for each each taking 1 step at a time.

Is it possible to use variables in a field calculation? If so how would I structure the formula to use them?

Jason

• ###### 1. Re: Calculations using Variables

Jason -

What I would suggest is to take a look at the Let statement. It allows you to put variables inside your calculation field. For example

Let ( [

var1 = Truncate ( BendDiameter / 12 ; 0 ) ;

var2 = BendDiameter - var1 * 12 ;

var3 = Truncate ( var2 / 1 ; ) ;

{ and so forth }

] ;

rest of calc here

)

HTH

Mike

• ###### 2. Re: Calculations using Variables

Mike,

Thank you it works perfectly

Jason

• ###### 3. Re: Calculations using Variables

Jason_Farnsworth wrote:

What I am trying to accomplish is taking a number that is in inches convert it to feet & inches for a printed display. I can do this with 5 seperate fields one for each each taking 1 step at a time.

I am not sure why this needs to take 5 steps. How about something like =

Div ( number ; 12 ) & " feet " & Mod ( number ; 12 ) & " inches"

• ###### 4. Re: Calculations using Variables

Micheal,

Your math routine works well except it drops the fraction off the end?

For instance 18.625

I would like to show it as 1' 6 3/4"

Also if I have 9.8125 I would like to show it as 9 13/16"

The real issues is I would like to enter all inches into the database as I collect data - purchasing and our vendors like to see things in feet and inches. So what I am trying to accomplish inch input with feet and inch with fractions printouts.

Currently I am using a fraction function that I made to get the fraction result.

I think that sorting data and looking for data is much simpler if it is standard to one unit.

Thanks

Jason

• ###### 5. Re: Calculations using Variables

Jason_Farnsworth wrote:

Currently I am using a fraction function that I made to get the fraction result.

Assuming the function works correctly, try =

Let ( [

ft = Div ( number ; 12 ) ;

in = Mod ( number ; 12 )

] ;

Case ( ft ; ft & "' " ) & Case ( in ; Fractions32 ( in ) & "\"" )

)

• ###### 6. Re: Calculations using Variables

Michael

This calculation is working very strange I am getting ramdon results

47.6875 returns 3' 187/16"

51 returns 4' "

48.375 returns 4' 3/8" which is correct

.5 returns 1/2" which is correct

Jason

• ###### 7. Re: Calculations using Variables

Micheal,

Let ( [

ft = Truncate (DiscriptionData1/12 ; 0) ;

math = DiscriptionData1-( ft * 12);

in = Truncate (math/1 ; 0) ;

fra = Fractions32 (math - in)

] ;

Case ( ft ; ft & "' " ) & Case ( in ; in  &   " " ) & Case ( fra ; fra & "''")

)

In this senerio it seams to be working well with one exception. When I only have feet and inches it doesn't add the " after the inch. If I have a fraction on the it it will add it.

Jason

• ###### 8. Re: Calculations using Variables

I can't comment without knowing what the Fractions32() function does.

• ###### 9. Re: Calculations using Variables

Function32

Case(

Round ( Number * 32 ; 0 ) = 32 ; " +1"; //fraction is closer to 1 than 31/32

Mod ( Round ( Number * 32 ; 0 ) ; 2 ) ; Round ( Number * 32 ; 0 ) & "/32" ; // some odd number of 32nds

Mod ( Round ( Number * 16 ; 0 ) ; 2 ) ; Round ( Number * 16 ; 0 ) & "/16" ; // some odd number of 16ths

Mod ( Round ( Number * 8 ; 0 ) ; 2 ) ; Round ( Number * 8 ; 0 )  & "/8" ; // some odd number of 8ths

Mod ( Round ( Number * 4 ; 0 ) ; 2 ) ; Round ( Number * 4 ; 0 ) & "/4" ; // some odd number of 4ths

Mod ( Round ( Number * 2 ; 0 ) ; 2 ) ; Round ( Number * 2 ; 0 ) & "/2" ; // 1/2

"" ) //fraction is closer to 0 than 1/32

• ###### 10. Re: Calculations using Variables

I see (hopefully). Yes, that looks like it should work - although I would point your atention to the Div(), Mod() and Int() functions.