Rather than adding spaces, I'd insert a single tab character.
So, add a calc field with the following calc:
tabChar = Char ( 9 ) ;
Substitute ( n ; [ "1" ; tabChar & "1" ] ; [ "2" ; tabChar & "2" ] ; [ "3" ; tabChar & "3" ] ; [ "4" ; tabChar & "4" ] ; [ "5" ; tabChar & "5" ] ; [ "6" ; tabChar & "6" ] ; [ "7" ; tabChar & "7" ] ; [ "8" ; tabChar & "8" ] ; [ "9" ; tabChar & "9" ] ; [ "0" ; tabChar & "0" ] )
which inserts a tab character before each digit; place this field on your layout and set its tab positions (centre aligned) so that the digits are centred in the boxes
.fp7 file attached
spacedNumber.fp7.zip 5.8 K
Thanks, Tom, getting close to the mark! I would not have worked this out if I'd had the rest of the year! : ) But, I have a sticking point, numbers are responding to the calculation beautifully however if I have a letter in the string it is not adjusting to it's tab position, it sticks right beside the preceding number on the left. Numbers following the letter continue to respond to the next tab position. The calculation is set for Text and no storage. Your example you kindly sent me responds the same way.
As these are character tabs I thought both letters and numbers would have responded the same way?
Many thansk for your thoughts,
1 of 1 people found this helpful
The calculation supplied is Substituting #'s only (assumes each # will be All Alone - in between tab stops), and letters are ignored / left where entered within Tab places.
You might try a different approach - so that when you WANT a TAB to occur, type a Space (space bar) in the string field:
tabChar = Char ( 9 ) ;
Substitute ( Self ; " " ; tabChar )
Thanks, David! How does this calc find the original string field? Are you saying the Space should be manually entered between each character in the original string field or in the calculated field on the form?
Thanks for helping,
Tom's calc is working like a charm if I could get it to recognise both numbers and text I'd be set!
Got it to work, David. Replaced 'Self' with the original field name and placed a space between each character in the original field then adjusted the tabs in the new calculated field, they now fit within the boxes.
This definately works, but I'll now have to get my users to add the spaces in the original fields for all the different strings that have to entered onto forms. I thought FMP would be clever enough to be able to space a string automatically, without manual involvement. I have great faith in FMP. : )
Many thanks for your exceedingly good suggestion.
John Rockstrom wrote:
To some (small) extent it can, by using the Extend style.
Why don't you define a calculation field =
Middle ( Extend ( YourField ) ; Get ( CalculationRepetitionNumber ) ; 1 )
Set the result type to Text and the number of repetitions to the number of boxes on your form. Place the field on the layout so that the repetitions align with the boxes.
In the interest of not having to retrain users to add spaces, I'll offer an alternate method using conditional formatting.
Set merge variables [I used <<$1>> thru <<$8>> on the layout in the position of the boxes.
Add a "declare variables" text object to the layout and attach conditional formatting to it to define the variables.
This object needs to be on the bottom layer of the layout, so send it to the back.
My formula is:
Let([ $1 = Middle(spacedValuesALT::EntryField; 1; 1);
$2 = Middle(spacedValuesALT::EntryField; 2; 1);
$3 = Middle(spacedValuesALT::EntryField; 3; 1);
$4 = Middle(spacedValuesALT::EntryField; 4; 1);
$5 = Middle(spacedValuesALT::EntryField; 5; 1);
$6 = Middle(spacedValuesALT::EntryField; 6; 1);
$7 = Middle(spacedValuesALT::EntryField; 7; 1);
$8 = Middle(spacedValuesALT::EntryField; 8; 1)
Get ( WindowMode ) < 4)
I added a second condition that sets the declare object to white text in all modes except layout.
Finally, to make the display instant, attach a script trigger on exit that refreshes the screen.
My example sets 8 boxes, but you could simply add to or take away from the formula to have as many boxes as needed.
This has the advantage of not having your users remember to space between certain types of characters, and it works with either number or letter.
spacedValuesALT.fp7.zip 6.8 K
I used this calculation "Middle ( Extend ( Pharmacy_Details::Pharmacy_approval number ) ; Get ( CalculationRepetitionNumber ) ; 10 )" which returned the original string but with no extended styling.
I tried to set 10 repititions at the base of the calc window which had no effect. If I used the ';1' as per your example it returned just the first character, when I changed it to ';10' it returned all the string (but with no spacing).
What am I missing?
John Rockstrom wrote:
I tried to set 10 repititions at the base of the calc window which had no effect.
What am I missing?
Most likely, you haven't placed all the repetitions on the layout. See the attached example.
String2Boxes.fp7.zip 6.6 K
Gotcha! Yes, missed the extending the repetitions in the Inspector. Works perfectly, thank you for the clarification.
And why aren't you doing something else on a Saturday evening? I have a perfect excuse, I'm a geek with nothing better to do. : )
This is a very nifty answer! I fiddled with conditional formatting earlier today but couldn't make it work for me, your suggestion is far more advanced than I would ever have figured out. For this immediate problem Michael's idea will suit me down to the ground but I will definately use your clever conditional formatting calc in other parts of my solution.
Thank you for taking the trouble to send the example, would never have figured it out without it (and even then it took me a while..)
At least I won't have to re-train those pesky users, they hate having to do new things! : )
You are welcome, John. I enjoyed the exercise. And kudos to Karen Weaver who originally put me onto the many uses of conditional formatting and merge variables.
Toms calc will Only allow 1 char per tab...
If that's livable, simply build out the calc to include all 26 letters...follow existing pattern, duplicate last bracketed section and replace 0's with a's, then a's with b's etc...
My formula assumes you can/want to have > 1 digit per Tab, and Yes manually enter a space in string -- I assumed you were manually entering numbers as well. the way i wrote it, it assumes the calc field IS the string field, it references itself, and will update on any change to the string. You could write a small looping script to accomplish inserting spaces ( or tabs) between ea char in string as a starting point, then go in and manually fine tune those that need a slightly diff pattern ( instead of 1 tab per character).
Sent from my iPhone
Why pad the data when you can simply pad the display. In the Inspector, under the appearence tab, use the 'indent' features for right or left indent of the desired field. You will achieve your alignment goal without messing with the data.