Jump to content

LeftRight Function


This topic is 2773 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I have two fields: Centimeters and Inches. I am trying to type in one (and vise versa), example (CM): 55-58 and then auto populate (IN) to 21.65-22.83. I was thinking using left or right function, but maybe there will be 3 or more digits in between the (-) symbol. What would be a good way to identify those digits in this case, so that I can apply the conversion vs script?

 

Thanks

Link to comment
Share on other sites

Use substitute to convert the hyphen to a return, then you can get the different numbers with GetValue:

Let ( [
    _values = Substitute ( Table::field ; "-" ; ¶ ) ;
    _left = GetValue ( _values ; 1 ) ;
    _right = GetValue ( _values ; 2 ) ;
] ;
    /* ... */
)

Link to comment
Share on other sites

Ideally, you would have four fields: Min_cm, Max_cm, Min_in and Max_in, and they would all be Number fields.

To do it with only two (Text) fields, as shown in your example, you could make the IN field auto-enter a calculated value (replacing existing value) =

If (
Get ( ActiveFieldTableName ) & "::" & Get ( ActiveFieldName ) = GetFieldName ( Self ) ; Self ;
Let ( [
v =  Substitute ( CM ; "-" ; ¶ ) ;
min = GetValue ( v ; 1 ) / 2.54 ;
max = GetValue ( v ; 2 ) / 2.54
] ;
Round ( min ; 2 ) & "-" & Round ( max ; 2 )
)
)

and a similar formula for the CM field. No scripts are required for this.

This assumes there will always be two values in the source field, separated by a hyphen - otherwise more work will be required to prevent the result being displayed as "21.65-0".

 

Edited by comment
  • Like 1
Link to comment
Share on other sites

This topic is 2773 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.