Microsoft KB Archive/103089

{| = How to Move the Cursor to the End of an @ ... EDIT Field =
 * width="100%"|

ID: Q103089

2.5x 2.60a | 2.5x 2.60 2.60a | 2.5x 2.60 2.60a

MACINTOSH | MS-DOS          | WINDOWS The information in this article applies to:
 * Microsoft FoxPro for Macintosh, versions 2.5x, 2.6, 2.6a
 * Microsoft FoxPro for MS-DOS, versions 2.5x, 2.6, 2.6a
 * Microsoft FoxPro for Windows, versions 2.5x, 2.6, 2.6a

SUMMARY
In order to facilitate text editing, you may need to place the cursor at the end of an edit region both upon entering a screen and upon moving to another record in the database. Listed below are two different methods of doing this.

Method 1
To begin editing at the end of a field created with @ ... EDIT, use the WHEN clause of the @ ... EDIT command to send CTRL+A and RIGHT ARROW keystrokes to the keyboard buffer.

Normally, the cursor will appear at the first character in the field when the cursor is moved to an @ ... EDIT field. However, if CTRL+A and the RIGHT ARROW key are pressed, the cursor will appear at the end of the data.

To automatically move the cursor whenever it enters of an @ ... EDIT field, these keystrokes must be sent to the keyboard buffer through the WHEN clause of the @ ... EDIT field.

NOTE: For the CTRL+A key combination to work properly, the FoxPro system menu must contain the Select All menu command (_MED_SLCTA) on the default Edit menu (_MSM_EDIT), and the shortcut key for the Select All menu command must be defined as CTRL+A.

The following code demonstrates how to move to the last character of an @ ... EDIT field.

SET SYSMENU TO  SET SYSMENU AUTOMATIC

DEFINE PAD medit OF _MSYSMENU PROMPT "Edit" COLOR SCHEME 3 DEFINE PAD mquit OF _MSYSMENU PROMPT "Quit" COLOR SCHEME 3 ON PAD medit OF _MSYSMENU ACTIVATE POPUP selectall ON SELECTION PAD mquit OF _MSYSMENU DO zzz

DEFINE POPUP selectall MARGIN RELATIVE SHADOW COLOR SCHEME 4 DEFINE BAR _MED_SLCTA OF selectall PROMPT "Select All" ; KEY CTRL+A, "CTRL+A" Y = 'This is a test' @ 2,2 GET x DEFAULT SPACE(10) @ 4,2 EDIT y DEFAULT SPACE(0) SIZE 4,20 WHEN yyy READ CYCLE

PROCEDURE yyy KEYBOARD "{CTRL+A}" KEYBOARD "{RIGHTARROW}" RETURN .t.

PROCEDURE zzz SET SYSMENU TO DEFAULT CLEAR READ

Method 2
In order to describe the steps necessary to create a screen that automatically moves the cursor to the bottom of an edit region, this method makes the following assumptions:


 * The database used by the screen is called CUSTOMER.DBF.
 * The memo field is called NOTES.
 * The first GET field in the screen is for the field CNO.
 * The first field and the EDIT region are not disabled.
 * A series of buttons is employed to navigate the database.

Upon executing a screen program, the first object activated is usually the first GET field. Therefore, the WHEN procedure of the first GET field will be used to send the cursor to the EDIT field. However, since you might want to enter data in the first GET field, a conditional test must be performed to allow this to happen only the first time the field is entered. To set up this condition, place the statement m.flag = .f. in the Setup code for the screen in the Screen Builder. By testing this variable in the WHEN clause of the CNO field (the first field) and then changing its value, you can allow entry into CNO instead of always jumping to the EDIT field. Placing the following code in the WHEN clause for the CNO field will accomplish this: IF ! FLAG _CUROBJ=OBJNUM(customer.notes) && moves cursor to EDIT field m.flag = .t.                   && allow access to CNO next time ENDIF Now that you have arranged to have your cursor move to the EDIT region, you are ready to perform the desired function; namely, moving the cursor to the bottom. In preparation, the EDIT region must be set so that the entire field is SELECTed ON ENTRY. Then, place the following code in the WHEN clause for the EDIT field: KEYBOARD("{DNARROW}") Because the entire field is selected, you only need to code one "down arrow" character to move to the bottom of the field. The only step remaining is to modify the VALID procedure for the navigation buttons. This code usually consists of a DO CASE statement to process the different buttons. Usually, the last statement in the VALID procedure will be SHOW GETS (used to refresh the screen). Add a line immediately before the SHOW GETS line as follows: _CUROBJ = OBJNUM(customer.notes) This is the same statement you used in the WHEN procedure of the first field to move the cursor to the EDIT field. When the screen is generated and run, every time you move to another record using the buttons, the cursor will be placed at the bottom of the EDIT field. Additional reference words: FoxMac FoxDos FoxWin SBuilder 2.50 2.50a 2.50b 2.50c 2.60 2.60a KBCategory: KBSubcategory: FxtoolSbuilder

Keywords         : kbcode FxtoolSbuilder Version          : 2.5x 2.60a | 2.5x 2.60 2.60a | 2 Platform         : MACINTOSH MS-DOS WINDOWS
 * }