Foxtools – Editor _EDGETLPOS

Version: 01.10.20 - last Update: Tuesday, October 13, 2009, 12:40:00

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


Foxtools Editor Support Functions

_EDGETLPOS

_EdGetLPos() Returns the byte offset from BOF for a line number (passed in <nLineNo> parameter)  in the editor session passed in <nWHAND> parameter.

VFP Syntax

nOffset = _EdGetLPos(nWHAND, nLineNo)

Parameters

[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] nLineNo

Line number to retrieve the byte offset for – counted from 1st line (line #0).

Returns

Numeric – the number of bytes from the beginning of file. The return value is zero-based.

Remarks

While evaluating the nLineNo parameter, _EdGetLPos() counts all lines in the editor’s text buffer from the 1st line #0. If nLineNo is greater than max lines, the byte offset to the beginning of the last line is returned! If one passes <0> for <nLineNo> then <0> is returned – as expected.

Note: Any negative <nLineNo> value passed in will return the byte offset to the beginning of the last line! Thus, this is a neat shortcut one can use to retrieve the byte offset to the last line without knowing how many lines are in a particular file.

VFP Example(s)

Opening an editor session, calculating total line count using _EdGetLPos() and _EdGetLNum():

*\\ Open editor session
nWHAND =_EDOPENFIL("TEST.TXT", 1)
*\\ get offset to BOL of last line
X = _EdGetLPos(m.nWHAND, -1)
*\\ y holds line number of last line (0-based)
Y = _EdGetLNum(m.nWHAND, m.X)
*\\ echo corrected (non 0-based) value to user
? "Total line count = " + TRANSFORM(m.Y + 1)
*//
*\\ 1-liner version:
? "Total lines ", _EdGetLNum(m.nWHAND, _EdGetLPos(m.nWHAND, -1)) + 1

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