8 Replies Latest reply on Jun 7, 2014 2:25 PM by Stephen Huston

    Scrolling Text Window from a Script


      I have a text field on a form layout with scroll bars. The field has much text within it. I am stuck trying to figure out how from within a script to scroll the text to a specific cursor position from within a script.


      I have in variables the cursor starting and selection size. The window is often scrolled to a position within the field such that the cursor position is not in view. How can I get the field view to scroll to a specified location?


      I tried the Set Selection command. Technically it changes the selection to the specified coordinates, but the text being viewed just resets to the top of the field, with the selected portion not in view. A manual scroll down, the selected text is not highlited although internally it is.


      I tried the Refresh Object. Does not scroll to the cursor position, just refreshes the data.


      Entering the field by click on the scroll bar forces the cursor to the end of the field. Updating Selection using the saved values has no visual effect (although internally it is selected) and does not cause a scroll to the location.


      So the question is how to get a text field to scroll to a specified cursor position from a script?

        • 1. Re: Scrolling Text Window from a Script
          Stephen Huston

          Could you be more specific about what you are trying to do? Your statements leve me confused about whether the user is IN the field or not. If there is a selection, then the field is active. If there is a cursor in the field, the cursor's position is normally within the visible window, though it may not automatically scroll to a specific position realtive to the top, but based on making the cursor visible, until the user manually scrolls it.


          Usually, providing the scroll bar allows the user to navigate at will. Activating a script while the cursor is active inside a field often changes the focus, depending on how the script is activated.


          What is your starting scenario and what you are trying to accomplish from there with a script?

          • 2. Re: Scrolling Text Window from a Script

            Assume a button to return to a saved position within the text. The user has scrolled down such that the saved position is out of view. The user clicks the button causing the text to scroll back to the saved position.


            Another case is a script wants to position the viewed text to a specific position because the script found something of interest to show the user.

            • 3. Re: Scrolling Text Window from a Script
              Stephen Huston

              I tested a few things , and these script steps worked for me:

              • Set Variable [ $select; Value: Get ( ActiveSelectionStart) ]
              • Set Variable [ $select[2]; Value: Get ( ActiveSelectionSize) ]
              • Go to Field [Select/perform; yourTable:Fieldhere]  (Select/Perform checked)
              • Set Selection [yourTable:Fieldhere; Start Postion: $select[1] ; End Position:
                $select[1] + $select[2] - 1
                I don't know quite why the "-1" was necessary to adjust the selection length to get it correct

              This left the field scrolled to the selection in my tests, even when the selection had been scrolled out of view.

              • 4. Re: Scrolling Text Window from a Script

                That worked. What I do not get is using the same Set Selection as a direct command from a button does not work, but in a script with the exact same syntax, it does work. However it is not highlighting the selection, but the cursor is at the correct position. I think it is because the Got To Field command does a selection whereas the command by itself does not default to using the entire text field.

                • 5. Re: Scrolling Text Window from a Script
                  Stephen Huston

                  Did you get both parameters of the Set Selection step set using the variables in the calcs I spelled out?


                  Be sure both Set Variables (including the [2] for repetition in the second variable with the same name) are set before the Go to Field step is performed.


                  If you are having trouble getting it to both start and extend the selection properly, try using the script debugger and data viewer to be sure your variables are correctly populated.


                  As for working with a button, that's problematic because a button is leaving the field, so the field and selection may not be active at the point the script executes following a button click.


                  The script as I posted it, is working for me every time, reselecting the exact selection which was scrolled out of view. However, I am executing it from the Script menu so as to not disrupt the field or it's selection. How to trigger it successfully may be an issue.

                  • 6. Re: Scrolling Text Window from a Script

                    Found the problem. I was using the value from Get(ActiveSelectionSize) directly. Have to add that to the cursor position. So lets say I selected 10 characters at position 25. The cursor position was 25, the size was 10.


                    I was passing the start position of 25; end position at 10. Changed my calculation for end position to


                    (start + size) -1


                    I too encountered the need for the minus 1 to get the correct selection.


                    It looks like it is working now.

                    • 7. Re: Scrolling Text Window from a Script

                      As far as capturing the position from a button, seems to work ok. I have a button (for test purposes) defined to execute a script. the script is simply


                      Set Field [table::start; Get(ActiveselectionStart)]

                      Set Field [table::end; ((table::start + Get(ActiveSelectionSize)) - 1)

                      • 8. Re: Scrolling Text Window from a Script
                        Stephen Huston

                        Glat to hear the button isn't the problem and that it's working now.