Mutiple break calculation

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

Recommended Posts

Quick Quesstion, I have a number that I want to be formatted automatically upon entry to keep everything the same. The number is 11 characters and broken up as 2,3,3,3 or eg 11 111 111 111. Now I have used a calculation

Let(
@NumbersOnly = Filter(Self; "0123456789");

Case(

Length(@NumbersOnly) = 10;

"("&""&

Left (@NumbersOnly; 2) &")"& "" &" "&

Middle(@NumbersOnly;3;4) & "-" &

Right (@NumbersOnly;4)

))

to format a phone number specifically and that is fine. But for the love of Mike how would I break up thea bove example to the 11 111 111 111 format when enterd as 11111111111

Share on other sites

Here's one way:

```Let (
digits = Filter ( Self ; "0123456789" )
;
Left ( digits ; 2 ) & " " & Middle ( digits ; 3 ; 3 ) & " " & Middle ( digits ; 6 ; 3 ) & " " & Right  ( digits ; 3 )
)```

Here's another:

```Let (
digits = Filter ( Self ; "0123456789" )
;
Replace ( Replace (  Replace (
digits ;
9 ; 0 ; " " ) ;
6 ; 0 ; " " ) ;
3 ; 0 ; " " )
)```

I did not test for length, because you didn't say what should be done when the test fails. In your example, the entry would have been erased - which is kind of cruel to the user.

• 1
Share on other sites

Thanks Comment, I have a cruel streak  Not really! I hadn't Picked up on that so will look but I will try your suggestion. I guess I wasn't sure how to deal with the 2 middle arguments. I wasnt sure if you could only have 1 instance but from your suggestion it appears that you can "nest" them for want of a better word. Thanks for your help as usual always prompt.

Share on other sites

You can concatenate as many Middle() function calls as you need. The name Middle does not refer to your calculation; it refers to the string from which the function will extract a "middle" part  (unlike the Left() or Right() functions, which will only extract a part from one of the string's ends).

Edited by comment
Share on other sites

Got it!. Thanks again comment.

Share on other sites

10 hours ago, comment said:

Here's another:

```
Let (
digits = Filter ( Self ; "0123456789" )
;
Replace ( Replace (  Replace (
digits ;
9 ; 0 ; " " ) ;
6 ; 0 ; " " ) ;
3 ; 0 ; " " )
)```

Nice use of Replace()  !!!!  :-)

Share on other sites

35 minutes ago, LaRetta said:

Nice use of Replace()  !!!!

Share on other sites

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

Create an account

Register a new account

• Similar Content

• Autoenter calculation. Text field. Knowledge missing.

By Enigma20xx,

• 9 replies
• 89 views
• Text field with a date embedded in some records

By Stickybeak,

• 2 replies
• 258 views
• Simple Calculation Question: Total Sum of hours per CLIENT

By Sharifa,

• 4 replies
• 544 views
• Problems with Reverse Calculation

By n7mafia,

• 4 replies
• 615 views
• How to generate different Portal line numbers for different parent record

By Guy_Smith,

• 4 replies
• 2,087 views
×
×
• Create New...