Using the Dollar Sign as a Relative Coordinate in FoxPro

ID: Q114134

The information in this article applies to:

SUMMARY

The dollar sign can be used to specify the current position in @ ... SAY/GET statements.

MORE INFORMATION

The dollar sign, when used in @ ... SAY/GET statements, returns the row and column of the active write cursor. This makes it possible to position objects relative to the initial position of the cursor.

In FoxBASE+, the write cursor defaults to line 21, and the column is set to 0. While this technique is static from the dot prompt, it is useful in programs for positioning objects relative to an offset. Issuing the following command will place an x at the dot of the dot prompt on the same line, which scrolls up:

   @ $, $ say 'x'

The next command will place the x at the top-left corner of the FoxBASE screen:

   @ $-21, $ say 'x'

In FoxPro 2.0 and 2.5 for MS-DOS and in FoxPro 2.5 for Windows, the behavior is different, in that the write cursor is placed on the desktop and can be used to position objects relative to the last cursor position. In this example, the text is first positioned at row 1/column 2, and then printed one row down and one column to the right:

   @ 1, 2 say 'x'
   @ $+1, $+1 say 'x'

Of course, as in FoxBASE, this is most useful in a program that requires relative positioning of objects.

Alternatively, the ROW() and COL() functions can be used to return the current cursor position, after which it can be incremented to produce offsets from the original position as follows:

   @ 1, 2 say 'x'
   @ ROW()+1, COL()+1 say 'x'

Additional reference words: FoxMac FoxDos FoxWin 2.00 2.50a 2.50b 2.60 2.10 replicate loop KBCategory: kbprg KBSubcategory: FxprgGeneral

Last Reviewed: June 27, 1995