4 Replies Latest reply on Dec 22, 2012 10:13 PM by mattb

    Programmatic text insert at cursor location - how might this be done in FMP?

    mattb

      Title

      Programmatic text insert at cursor location - how might this be done in FMP?

      Post

           I would like to be able to programmatically insert text in an existing text field at the cursor's current location .  Problem is that I don't see any FMP functions that would return the value of the cursor's current position in a field.  If I were able to ascertain that number, then I would use Left, Middle, and/or Right functions to insert the text at the proper location, i.e. splitting the existing text, with the programatically inserted text in between, and then using Set Field.  Currently I'm only able to insert programatically inserted text at the end of an existing text field, initiated by a mouse click on another text field that runs a script. 

           Background:  I'm the developer of a cross-platform application, the Windows version is written in Visual Foxpro and the Mac version in FMP.  The way I accomplish this in VFP is using their "KEYBOARD" command which simply stuffs the keyboard buffer with the predetermined text, and when activated by a hotkey or mouse click, it inserts the predetermined text at the cursor's current location in the text field, which then pushes any existing text past the cursor's location to be below the inserted text.  In this case, VFP doesn't even know the current position of the cursor in the field, but it doesn't matter, because the KEYBOARD function just inserts the text wherever the cursor is.

           Any ideas on how to accomplish this same task in FMP?  I'm thinking if FMP can provide me with a number that represents the cursor's current position in a text field, I could do it, but short of having that vital piece of info, I'm stumped.  Any suggestions?

            

            

            

            

            

            

        • 1. Re: Programmatic text insert at cursor location - how might this be done in FMP?
          philmodjunk

               The insert script steps can insert data at the current cursor location if you do not specify a target field.

               On the other hand, whenever you find yourself looking for a function make sure to check the list of get functions:

               Get(ActiveSelectionSize)
               Get(ActiveSelectionStart)

          • 2. Re: Programmatic text insert at cursor location - how might this be done in FMP?
            mattb

                 Hi Phil -

            The insert script steps can insert data at the current cursor location if you do not specify a target field.

                 I think you meant "Insert Text"?  There is no "Insert Script" step that I can see.  At any rate, it doesn't work because the value I'm trying to insert comes from another field and this step literally inserts the field name instead of the contents of the field.  I tried stuffing the contents of field into a variable and then issuing the Insert Text step with the variable name with the same results, i.e. the variable name got inserted instead of the variable contents.  Then I tried "Insert Calculated Result" and that did work with variable, but as you mentioned, if the target field is specified, it inserts at the bottom, which is not what I want.  Because of my method of triggering this insert (clicking the mouse on a field outside of the text field in question), leaving the target field unspecified doesn't work because the focus has temporarily been moved away from field that needs the insertion (even when issuing a Goto Field step prior to the Insert Calculated Result).  So...still stumped.

            Get(ActiveSelectionSize)
                 Get(ActiveSelectionStart)

                 I was aware of these steps, but don't they require the text in question to be highlighted first?  I can't have users highlighting portions of text in order to successfully perform a text insertion...

            • 3. Re: Programmatic text insert at cursor location - how might this be done in FMP?
              philmodjunk

                   I meant the script steps that start with "insert" as the first word. Insert Calculated result, as you have discovered, can reference another field.

                   Clicking a button leaves the focus unchanged so you can use Insert Calculated Result from a button to insert data at the current insertion point in the active field.

                   Get ( ActiveSelectionStart )

                   returns the position of the cursor if no text is selected. (And then the selectionsize function returns a seleciton size of 0).

              • 4. Re: Programmatic text insert at cursor location - how might this be done in FMP?
                mattb

                     Yes, I arrived at the same solution after a little more experimentation.  Thanks!