Bottom of Listbox.

I’m trying to figure out how to keep the last lines of a listbox on the bottom.
It seems there is a propertery called scroll position which is the row number of the top of the listbox as it is currently displayed.
But I think there is a need to know how many lines are displayable by the listbox in its current state…
If I know what lastindex is… but… not sure how to calculate the number of lines displayed.

If you know the height of the listbox and the rowheight you can figure it out.

listbox height / row height

(if you have header in the listbox you need to recalculate)

BO’B and all interested parties, I find the following “works”:

'scroll down if space filled
dim h, hh as UInt16 'regardless of unit of measure, height cannot exceed 65 thousand pixels
dim max, topindex as UInt64 'allow for 0 to 2^64-1 elements :-p
h = ListBox1.RowHeight 'height of each individual row occupying available space
hh = ListBox1.Height - ListBox1.HeaderHeight 'height of available space accounting for header
if h <> 0 then 'avoid divide by zero (a row height of 0 pixels does not exist but just in case)
max = (hh/h) - 1 'the row count from top to bottom of the visible area adjusted for zero based indexing
if not (ListBox1.LastIndex < max) then 'do not adjust if the last row falls before the max allowable rows
topindex = ListBox1.LastIndex - max 'count back the number of visible rows to calculate the index of the top row
ListBox1.ScrollPosition = topindex 'set the top visible row to be the row that should now occupy the topmost position
end if 'not (ListBox1…)
’ do nothing in the event of a row height of 0 (not a real situation?)
end if 'h <> 0…

Is it more readable displayed as code ?

No (code removed)