Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

On key label - Additive 1

Status
Not open for further replies.

keepingbusy

Programmer
Apr 9, 2000
1,470
GB

I am trying to force the cursor to the end of the text in an edit window and in particular, down to the next line as in a carriage return.

Code:
* mytext is a memo field

mf1="MY NAME"

on key label f5 replace mytext with trim(mf1)+":"+ ;
  chr(13)+chr(13)
This does add "MY NAME" to the contents of the memo field but puts the cursor above the line just added.

Any suggestions please guys?

VFP9

Thank you
Lee
 
Is the Memo Field Open in an Object, in a window, as Modify Memo at the time of the replacement?

David W. Grewe Dave
 

Dave
Is the Memo Field Open in an Object, in a window, as Modify Memo at the time of the replacement?
The memo field is on a form in an edit window with other fields.

ilyad
Try keyboard '{Ctrl + End}'
I am trying to automate the process so user don't have to use combination keys.

The idea of this is when a user is typing in a statement on the open form and into the memo field, I have assigned different names (JOHN JONES, PETE EVANS etc) to function keys (F5, F6 etc). Each time the users name is required to be entered at a particular section of the statement, an F key is used. I then want the cursor to go beyond the name and carriage return to the next line.

Thank you
Lee

 
Lee,

When you say it is an "edit window", do you mean it's an edit box on a form?

If so, one solution might be to write something like this, and to fire it from the Keypress of the form:

THISFORM.MyEditBox.Value = "My Name" + chr(13) + chr(13)
THISFORM.MyEditBox.SelStart = 0
THISFORM.MyEditBox.SetLengh = LEN(THISFORM.MyEditBox.Value)

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Hello Lee:

If all these keys are getting assigned in a form, my suggestion would be to create a method on the form.

Pass the Keylabel to the method. Put a case statement and based upon the key do the needfull.

For the f5 editbox problem the following will do it:
this.edit1.Value = "My Name"
this.edit1.SelStart = LEN(ALLTRIM(this.edit1.Value))+1
KEYBOARD '{ENTER}'
this.edit1.setfocus()
 
In the code that does the assignation simply add code I posted as the last line.

Or you can use SelLength approach as shown by others, but then you would need to pass an object reference to your editbox into the procedure.
 

Mike
When you say it is an "edit window", do you mean it's an edit box on a form?
Yes. Sorry, it's been a long day.

Imaginecorp/ilyad

I'll look at all the sugestions over the next few days and post back soon.

Thanks guys

Lee
 

Mike: If I place the code in the keypress event on the form, how do I fire it. The help file doesn't give a lot away and also if there is more than one Function key in use, how do I overcome that?

ilyad:
Or you can use SelLength approach as shown by others, but then you would need to pass an object reference to your editbox into the procedure.
Could you please expalin this?

imaginecorp:
Pass the Keylabel to the method. Put a case statement and based upon the key do the needfull.
I've not had any experience doing what you have suggested, please could you expand a little?

Some guidance, not the sollution would be most helpful.

Thanks all

Lee
 
Keepingbusy,

Just put the code
Code:
THIS.SelStart = Len(This.Value)
THIS.Sellength = 0
in the when() event and perhaps also in the mousedown event() of the editbox, then the cursor is at the end position, when the user activates the editbox.

Bye, Olaf.
 
Lee,

If I place the code in the keypress event on the form, how do I fire it. The help file doesn't give a lot away and also if there is more than one Function key in use, how do I overcome that?

You don't fire the keypress. You add code to it. Something like this:

Code:
LPARAMETERS nKeyCode, nShiftAltCtrl
DO CASE
  CASE nKeyCode = -1
    * F2 pressed.
    * Take appropriate action for F2
  CASE nKeyCode = -2
    * F3 pressed

    *** etc
ENDCASE

Put that in the Keypress of the form. Also set the form's KeyPreview to .T. Then way, whenever the user presses one of the relevant keys (F2, or whatever) while the form is active, your code will execute.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 

Thank you for the responses. I ran with Olafs suggestion by putting the following code in the editbox events when and mousedown:
Code:
THIS.SelStart = Len(This.Value)
THIS.Sellength = 0

On the form is a command button which assigns a name to a function key e.g.
Code:
STORE SPACE(20) TO mf4, mf5, mf6, mf7, mf8
DO FORM FKEYS WITH mf4, mf5, mf6, mf7, mf8
IF NOT EMPTY(mf4)
  ON KEY LABEL F4 REPLACE MG15TEXT WITH ;
    CHR(13)+TRIM(mf4)+":"+CHR(13) ADDITIVE
ENDIF
IF NOT EMPTY(mf5)
  ON KEY LABEL F5 REPLACE MG15TEXT WITH ;
    CHR(13)+TRIM(mf5)+":"+CHR(13) ADDITIVE
ENDIF
* More code F6 F7 etc....
This had the desired effect when a user pressed the appropriate function key and the cursor moved below the name.

Thanks again guys.
Lee

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top