11 Replies Latest reply on Apr 5, 2010 9:14 AM by mrvodka

# Converting inches to centimeters - script

### Title

Converting inches to centimeters - script

### Post

I am creating a database that will contain information about an art collection.  I have fields established for dimensions.  In Field A, I will manually type in dimensions in inches:  A x B x C".  In Field B, I want those inches to automatically convert to centimeters and populate that field. How do I go about creating a script for this?!

Help!

And thanks!

• ###### 1. Re: Converting inches to centimeters - script

howdy glitter,

Depending on how you would use this, you may choose not to have a script.

If you make three new fields (FieldAcm, FieldBcm, FieldCcm) as calculation fields returning numbers, you can simply define the fields as

= FieldA * 2.54 for field Acm

= FieldB * 2.54 for field Bcm

etc.

This will work well for you with no script.

If, however, you will perform searches on this field, you may want to avoid this calc field since it may slow your searches.  If this is the case, launch an OnObjectModify script on each field that runs a script like:

SetField (Table::FieldAcm ; Table::FieldA * 2.54)

Is this what you're after?

• ###### 2. Re: Converting inches to centimeters - script

Hi Ninja!

This is SO helpful.  Thank you so much for your quick reply.  This makes sense to me up to the point where I need the new inches fields and the centimeter fields to "see" each other.  How do I connect the two?  Thanks again!!

• ###### 3. Re: Converting inches to centimeters - script

howdy glitter,

If you chose to make the cm field a calc field, in the same table, the "seeing" is done in the calculation you define.

FieldAcm = FieldA * 2.54

If doing it via script, the fields don't need to "see" each other.  The script takes the value from FieldA, multiplies it by 2.54 then shoves it into the other field (FieldAcm).

no connection is needed outside of this.  There is no relationship connection needed in order to do what you describe since the fields are already on the same record in the same table.

• ###### 4. Re: Converting inches to centimeters - script

You rock so hard.  THANKS!  Will post again if I get stuck!

• ###### 5. Re: Converting inches to centimeters - script

Okay!  Everything is performing beautifully.  Thanks so much!!

• ###### 6. Re: Converting inches to centimeters - script

EEK!  One last question!  Is there a way to limit the centimeters to only two numeric values past the decimal?  Thanks!

• ###### 7. Re: Converting inches to centimeters - script

If you care about the precision then you wouldnt change the real result but rather format the calc field to only show 2 decimal places. Click the field and look under numer formatting.

If you only want it to return two decimal places then use Round ( FieldA * 2.54; 2 ) or Truncate ( FieldA * 2.54; 2 ), depending on what you like.

• ###### 8. Re: Converting inches to centimeters - script

Thanks, Mr. Vodka!  That was really helpful.  Here is my final question (I hope!):

How do you get the formula to behave properly when using fractions?

Example: 8 inches converts nicely to 20.32 cm.  However, 8 1/8 converts to 2077.72 and I want it to read 20.77.

Any ideas?  I really don't want to convert the fractions to decimals if at all possible (I really do want 8 1/8" vs. 8.125").

THANKS!!!

• ###### 9. Re: Converting inches to centimeters - script

I dont quite understand what you are asking.

8 1/8 is actually 8 + 1/8 or 65/8.

I have no clue where you are even getting the 2077.72 figure from. Shouldnt it be 20.6375?

• ###### 10. Re: Converting inches to centimeters - script

FWIW,

818 inches = 2077.72 cm

It looks like the typed fraction either does not have, or is ignoring the /

• ###### 11. Re: Converting inches to centimeters - script

Lol. Should have checked that.

To silver_slippers_glitter:

Yes that would be the typical result if that was put in a number field. If you are going to use fractions you should probably enter it into a text field. Then you can probably modify your calc to be something like:

Round ( Evaluate ( Substitute ( Trim ( YourMixedNumberField ); " "; "+" ) ) * 2.54; 2 )