Foxtools – Editor _EDGETLNUM

Version: 01.10.00 - last Update: Tuesday, October 13, 2009, 12:35:00

Previous ChapterFoxtools Home (Alphabetical TOC)Foxtools Home (Grouped TOC)Next Chapter See also:_EdGetChar | _EdGetLPos | _EdGetPos | _EdGetStr | _EdPosInVi | _EdSkipLin

Foxtools Editor Support Functions


_EdGetLNum() Returns the line number of a byte offset (passed in <nPosition> parameter)  in the editor session passed in <nWHAND> parameter.

VFP Syntax

nLineNo = _EdGetLNum(nWHAND, nPosition)


[in] nWHAND

Fox-window handle of the editor session in question. If nWHANDL is no valid editor-session handle, an error “API call caused an exception” (Error 2028) is raised.

[in] nPosition

Offset position (byte count) from beginning of the file. <nPosition> value is zero-based. CRs @ EOL are counted as well.


Numeric – the number of the line with the <nPosition> offset. The return value is zero-based. Thus, one has to add 1 to get the actual line number like so:
   lnCaretLine = _EDGETLNUM(m.nWHAND, _EDGETPOS(m.nWHAND)) + 1
Adding 1 is only useful, if one wants to display the result to an end-user. Internally all routines work with zero-based offsets and counting. Thus, it’s better to keep the zero-based approach throughout all Foxtools editor functions.


While evaluating the nPosition parameter, _EdGetLNum() counts all characters in the editor’s text buffer from the beginning starting with value 0. Thus, the very first character in the buffer hast a nPosition value of <0>. CRs at the end of each line are counted as well! It makes no difference if one has checked “Save with line feeds” in Edit Properties dialog, coz VFP drops all LFs while loading the file content into its editor buffer. Normally, one uses the caret’s position value returned by _EDGetPos() for <nPosition> value.

Let’s look at an editor session with “display white spaces” set ON:

Row#1:     A¶ | 1 character  + 1 CR = 2
Row#2:     AB¶ | 2 characters + 1 CR = 3
Row#3:     ABC¶ | 3 characters + 1 CR = 4
Row#4:     ABCD¶ | 4 characters + 1 CR = 5
Row#5:     ABCDE¶ | 5 characters + 1 CR = 6
_EdGetLNum() results

Note: If nPosition points to the end of the editor’s text buffer (@ EOF) or beyond EOF, then always the highest line number (0-based) is returned! If one passes <0> or even a negative <nPosition> value, always <0> is returned.

VFP Example(s)

Opening an editor session, comparing complementary functions _EdGetLPos() and _EdGetLNum():

*\\ Open editor session
*\\   use file content like shown above
*\\ let's compare _EdGetLNum() and _EdGetLPos() 
FOR lnLineNo = 0 TO 5
   *\\ x holds offset of BOL of line# <lnLineNo>
   X = _EdGetLPos(m.nWHAND, m.lnLineNo)
   *\\ y holds line number of offset pos <m.X>
   Y = _EdGetLNum(m.nWHAND, m.X)
   *\\ m.Y and m.lnLineNo must be identical
   ? m.Y = m.lnLineNo

Previous ChapterFoxtools Home (Alphabetical TOC)Foxtools Home (Grouped TOC)Next Chapter