Text Insert with VFP 9

Hi all. I've been trying to get insertion to work within a text box, so that user input text will be inserted at the current cursor position.

For example we have two textboxes. Textbox 1 is pulled from a db and contains the string "This is what is all about"

Textbox 2 allows user input and the user types the word 'life'

User clicks within textbox 1 to set the cursor position after the word 'what'

By clicking a command button, I would like 'life' to be inserted at the current cursor position, to make the sentence read "This is what life is all about."

This is just an example as the actual text lengths will vary in use.

I've been working with SelStart and I can get the text inserted at the end of the sentence, but not within the body of it. Can someone please help?
formadmirerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GreatSolutionsC.I.OCommented:
Not tested, but something as follows should work:
Assuming you have a nDesiredPosition variable, in the button's click, please enter:

ThisForm.txtBox1.SelStart = nDesiredPosition
keyboard ThisForm.txtBox2.Value
ThisForm.txtBox1.SetFocus()

Hope this helps
Jaime

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tusharkanvindeCommented:
STUFF(thisform.txtbox1.value,thisform.txtbox1.selstart,0,thisform.txtbox2.value)
formadmirerAuthor Commented:
Thanks for the reply. I continued working with it since I posted and was able to get it to insert the text where I wanted. Different than what you posted, but it works.

The only thing is it needs to advance the cursor to the end of the entire text so the user can continue typing.

Any idea how to insert the cursor - or advance the cursor - to a predetermined point?
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

peterhuppCommented:
one way to do this is with a keyboard command.

In the gotfocus() method of your textbox1

   *    I would add:

   KEYBOARD replicate('{RIGHTARROW}',lnStartPosition) PLAIN CLEAR

  *    where lnStartPosition is how far you want the cursor to be in the textbox
 
peterhuppCommented:
Just saw your last post Formadmirer,


To move the cursor to the end of the text  I would do this keyboard command  in the gotfocus method of your textbox.

 KEYBOARD '{end}' PLAIN CLEAR
formadmirerAuthor Commented:
Thanks all - got it using a conglomeration of SUBSTR and LENs

Points for taking the time to help - I do appreciate it.
formadmirerAuthor Commented:
I ended up getting this on my own - no fault of the experts - it's just I was working as I posted and eventually got it.
tusharkanvindeCommented:
to move cursor use

ThisForm.txtBox1.SelStart =len(alltrim(ThisForm.txtBox1.value))
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
FoxPro

From novice to tech pro — start learning today.