Am I scrolled?

I’m writing an app that keeps appending text to a read-only TextArea. (That data is streaming from a running Shell, but that’s not important.) I want the TextArea to keep scrolling as new data is added, but only if the user hasn’t scrolled up. In other words, if the user has moved the scrollbar to the top or middle of the TextArea to read something, I don’t want it suddenly jumping back to the bottom as new data appears. Likewise, if the scrollbar is already at the bottom, I want it to scroll as the new stuff rolls in.

Definitely without plugins (it’s an open-source project) and preferably without declares, how can I tell the relative position of the scrollbar?

And here is the answer:

// See if the last character is visible
dim lineNumOfLastVisible as integer = _
    fldOut.LineNumAtCharPos( fldOut.CharPosAtXY( 0, fldOut.Height - 9 ) )
dim lineNumOfLastChar as integer = _
    fldOut.LineNumAtCharPos( fldOut.Text.LenB )

fldOut.AppendText data

if lineNumOfLastChar = lineNumOfLastVisible then
  fldOut.ScrollPosition = 1000000000
end if

Note that I use LenB because, in my case, the output is always ASCII and LenB is faster than Len.