I can tell you a much simpler one
dim LineStart() as long
'After the textbox is loaded, CALL THIS FUNCTION
private sub LoadLineNumbers()
dim temp as long
dim curInd as long
rtbbox.SelStart=0
do while curInd<=len(rtbbox.text)
redim Preserve LineStart(0 to temp)
LineStart(temp)=curInd
rtbbox.Upto chr(13)+chr(10),true,false
rtbbox.selstart=rtbbox.selstart+2
curInd=rtbbox.selStart
temp=temp+1
loop
end sub
'If you execute this routine you'll have all the line start positions in the array
'Now if you want to get a particular line into a sstring just call this function with line 'number
private function GetTheLine (lineNo as long) as string
if lineNo>UBound(LineStart)+1 or lineNo<=LBound(LineStart) then
dim temp as long
rtbbox.selstart=LineStart(lineNo-1)
rtbbox.Upto chr(13)+chr(10),true,false
temp=rtbbox.selstart
rtbbox.selstart=LineStart(lineNo-1)
rtbbox.selLength=temp-rtbbox.selstart
GetTheLine=rtbbox.seltext
rtbbox.sellength=0
else
msgbox "Error in accessing the line number",vbCritical
end if
end function