1 2 3 Previous Next 40 Replies Latest reply on Sep 10, 2016 4:48 AM by beverly

    Add a carriage return after every character

    Rick_Stringer

      I have a field that I want to force a carriage return after every character, except for the last character. I'm stumped as to how to do that.

        • 1. Re: Add a carriage return after every character
          beverly

          force? by auto-enter, calc or script trigger?

           

          beverly

          • 2. Re: Add a carriage return after every character
            philmodjunk

            If you want this to happen as they type it in, you might use the OnObjectKeystroke trigger.

             

            Set Field [YourTable::YourField ; YourTable::YourField & Get ( TriggerKeystroke ) & ¶ ]

            Exit Script [False]

             

            The last step keeps the "triggering event"--in this case a key stroke from being process after the script completes. Without that step, every keystroke would be doubled in this case.

            • 3. Re: Add a carriage return after every character
              Rick_Stringer

              When I do that, it replaces each of the previous keystrokes. I want it to be able to keep the previous keystrokes. Like this:

              1

              2

               

              3

              4

              5

               

              There is the possibility of having multiple returns where needed, and the multiple returns could even be at the beginning. I'm fine with it doing all of this as any script trigger.

              • 4. Re: Add a carriage return after every character
                philmodjunk

                Open this thread in your browser rather than your email. I made a last second edit to the script example after already posting my response. The change that I made addresses that issue.

                • 5. Re: Add a carriage return after every character
                  Rick_Stringer

                  I did open it in my browser. Here is how I have the script:

                   

                  Set Field [ MyTable::MyField ; Get ( TriggerKeystroke ) & ¶ ]

                  Exit Script [ Text Result: False ]

                  • 6. Re: Add a carriage return after every character
                    philmodjunk

                    Better look again, you do not have my last change to the script which I added literally seconds after I clicked "Post".

                     

                    Copy and pasting:

                    Set Field [YourTable::YourField ; YourTable::YourField & Get ( TriggerKeystroke ) & ¶ ]

                    Exit Script [False]

                    • 7. Re: Add a carriage return after every character
                      beverly

                      the only "problem" with the script (in my test) was that the backspace just produced another return. and there is no editing "inline", if you want to add values other than at end. But the return produced a return with the automatic return (two returns). Two returns entered produced 4 returns, etc.

                       

                      Did you test Phil's example?

                      beverly

                      • 8. Re: Add a carriage return after every character
                        philmodjunk

                        good point, you'd need to test for such special keystrokes and I can testify from experience that getting such OnObjectKeystrokes scripts working smoothly for all possible inputs can produce a complex script--unlike my very simple example as you need to test the character (or it's code) to handle things like arrow and delete keys.

                        1 of 1 people found this helpful
                        • 9. Re: Add a carriage return after every character
                          Rick_Stringer

                          Yes, I am experiencing what Beverly pointed out. It is progress, just not exactly what I need yet.

                           

                          Thank you for everything so far.

                          • 10. Re: Add a carriage return after every character
                            Rick_Stringer

                            The other problem that I'm seeing is that you can't add a character somewhere in the middle. I guess this is not nearly as simple as I had hoped it would be.

                            • 11. Re: Add a carriage return after every character
                              philmodjunk

                              An example of how to modify this so that the backspace stroke deletes a character:

                              Set Variable [$Key ; value: Get ( TriggerKeystroke ) ]

                              If [ Code ( $Key = 8 //code for back space ]

                                 Set Field [YourTable::YourField ; Left ( YourTable::YourField ; length ( YourTable::YourField ) - 2 ]

                              Else

                                 Set Field [YourTable::YourField ; YourTable::YourField & $Key & ¶ ]

                              End If

                              Exit Script [False]

                               

                              Note that you'll need to add "else If" steps for each keystroke that requires special handling. Handling cursor position due to pressing the arrow key or a user clicking/tapping into the field especially complicates the script. The above example assumes that the cursor is always after the last character in the file. Get ( selectionStart) can tell you the current cursor position, but be warned, each of these details greatly adds to the complexity of the script. If, in the name of keeping the script simpler, you want to disable certain keystrokes use the code similar to the following, which disables the left arrow key:

                               

                              Else IF [ code ( $Key ) = 28 // code for left arrow ]

                                 Exit Script [False]

                              Else If [....

                               

                              Since this is an unusual method of data entry, you might also describe the purpose behind this. There might be an alternative approach that makes this much simpler to implement.

                              • 12. Re: Add a carriage return after every character
                                beverly

                                that's what I meant by "inline"

                                - after typing 12 4 and getting returns after each one, i cannot click after 2 and type 3, it ends up at the end of the field

                                 

                                The script/calc also does not clean up the final return (as originally requested) after completion. So how would we know this is the end of the entry?

                                 

                                I was trying to not use triggers for keystrokes, but allow normal entry and then when exiting field, trigger a replacement of each character with the character & return. I believe that would allow editing, but you'd have to be careful to NOT duplicate the previous replacements, just the new characters added.

                                • 13. Re: Add a carriage return after every character
                                  philmodjunk

                                  you could detect the "exit" event or use an auto-enter calculation to strip off the last return--a detail that I missed.

                                   

                                  But I agree with Beverly that there are simpler options to consider--such as a mouse click on the field opening up a popover where a field shows the current data as: "ABCDE" and the user edits like any other text field. But when the popover closes, a script or calculation produces:

                                  A

                                  B

                                  C

                                  D

                                  E

                                   

                                  But an understanding of why you want this feature can help us to better help you.

                                  • 14. Re: Add a carriage return after every character
                                    Rick_Stringer

                                    It is for a database that we use for tracking signage. There are two fields side by side. The one on the left is for directional arrows. It uses a custom font that we created years ago for that purpose. The second field is for the messaging on the signs. Each arrow in the first field has to line up with a specific line of text in the second field.

                                     

                                    I hope that make sense.

                                    1 2 3 Previous Next